pip freeze creates some weird path instead of the package version
It looks like this is an open issue with pip freeze
in version 20.1
, the current workaround is to use:
pip list --format=freeze > requirements.txt
In a nutshell, this is caused by changing the behavior of pip freeze
to include direct references for distributions installed from direct URL references.
You can read more about the issue on GitHub:
pip freeze does not show version for in-place installs
Output of "pip freeze" and "pip list --format=freeze" differ for packages installed via Direct URLs
Better freeze of distributions installed from direct URL references
Pip freeze shows a weird version of a package
As @Corralien pointed out it's not that weird to have a post-release version of something: https://www.python.org/dev/peps/pep-0440/#version-scheme
Post-releases are usually made to make some minor change to the released package that does not affect the code necessarily (e.g. a typo in the readme, or some other minor packaging bug).
It is a little weird in this case because on PyPI there is no 52.0.0.post20210125
release for setuptools. There is, however, a 51.1.0.post20201221 release which was apparently made by mistake.
I don't know how you ended up with the one you have though. It does not appear to exist (maybe it was deleted).
You should try upgrading setuptools before freezing your pip environment since the one you have is outdated anyways.
pip freeze requirements with some local file location
I would try the following instead:
pip list --format=freeze > requirements.txt
pip freeze does not show all installed packages
I just tried this myself:
create a virtualenv in to the "env" directory:
$virtualenv2.7 --distribute env
New python executable in env/bin/python
Installing distribute....done.
Installing pip................done.
next, activate the virtual environment:
$source env/bin/activate
the prompt changed. now install fabric:
(env)$pip install fabric
Downloading/unpacking fabric
Downloading Fabric-1.6.1.tar.gz (216Kb): 216Kb downloaded
Running setup.py egg_info for package fabric
...
Successfully installed fabric paramiko pycrypto
Cleaning up...
And pip freeze
shows the correct result:
(env)$pip freeze
Fabric==1.6.1
distribute==0.6.27
paramiko==1.10.1
pycrypto==2.6
wsgiref==0.1.2
Maybe you forgot to activate the virtual environment? On a *nix console type which pip
to find out.
What are the file annotations in a pip requirements.txt file?
Please check out this command :
pip list --format=freeze > requirements.txt
For more information read this github discussion
From virtualenv, pip freeze requirements.txt give TONES of garbage! How to trim it out?
That is one thing that has bugged me too quite a bit. This happens when you create a virtualenv without the --no-site-packages
flag.
There are a couple of things you can do:
- Create virtualenv with the
--no-site-packages
flag. - When installing apps, dont run
pip install <name>
directly, instead, add the library to yourrequirements.txt
first, and then install the requirements. This is slower but makes sure your requirements are updated. - Manually delete libraries you dont need. A rule of thumb i follow for this is to add whatever is there in my
INSTALLED_APPS
, and database adapters. Most other required libraries will get installed automatically because of dependencies. I know its silly, but this is what I usually end up doing.
-- Edit --
I've since written a couple of scripts to help manage this. The first runs pip freeze and adds the found library to a provided requirements file, the other, runs pip install, and then adds it to the requirements file.
function pipa() {
# Adds package to requirements file.
# Usage: pipa <package> <path to requirements file>
package_name=$1
requirements_file=$2
if [[ -z $requirements_file ]]
then
requirements_file='./requirements.txt'
fi
package_string=`pip freeze | grep -i $package_name`
current_requirements=`cat $requirements_file`
echo "$current_requirements\n$package_string" | LANG=C sort | uniq > $requirements_file
}
function pipia() {
# Installs package and adds to requirements file.
# Usage: pipia <package> <path to requirements file>
package_name=$1
requirements_file=$2
if [[ -z $requirements_file ]]
then
requirements_file='./requirements.txt'
fi
pip install $package_name
pipa $package_name $requirements_file
}
Related Topics
How Can One Find the Unicode Codepoints That a Font Has Glyphs For, on a Debian-Based System
Different Yaml Array Representations
Find in Files Using Ruby or Python
Aes Python Encryption and Ruby Encryption - Different Behaviour
How to Import a JSON from a File on Cloud Storage to Bigquery
Rally APIs: How to Copy Test Folder and Member Test Cases
Python VS. Ruby for Metaprogramming
How to Write a Perl, Python, or Ruby Program to Change the Memory of Another Process on Windows
Convert Backward Slash to Forward Slash in Python
What's the Ruby Equivalent of Python's Os.Walk
Restrictons of Python Compared to Ruby: Lambda'S
Efficient Ways to Duplicate Array/List in Python
Python Equivalent of Ruby's Each_Slice(Count)
Import Arbitrary Python Source File. (Python 3.3+)
Merge Pandas Dataframes Where One Value Is Between Two Others
Pyinstaller Unable to Access Data Folder