Warning: cannot find svn location for distribute==0.6.16dev-r0 - python

I am getting the following error with that command:
$pip freeze > requirements.txt
Warning: cannot find svn location for distribute==0.6.16dev-r0
This is my requirements.txt file beforehand:
Django==1.3
django-registration==0.7

First, I'd note that is not an error, but rather a warning (though it is a serious one).
This appears to be an open issue in pip, judging by this issue page on the github repository. The problem arises when pip is installing something a development version that is held on a repository that is not SVN. One example that issue page provides:
mkvirtualenv test --no-site-packages
workon test
pip install flask==dev
pip freeze > requirements.txt
It will print this result to standard error:
Warning: cannot find svn location for Flask==0.9-devdev-20120114
But the file will still have:
## FIXME: could not find svn URL in dependency_links for this package:
Flask==0.9-devdev-20120114
Jinja2==2.6
Werkzeug==0.8.2
wsgiref==0.1.2
However, I won't be able to use this file in the future to install Flask. See here:
mkvirtualenv test2 --no-site-packages
workon test2
pip install -r requirements.txt
Will output the error:
Downloading/unpacking Flask==0.9-devdev-20120114 (from -r requirements.txt (line 2))
Could not find a version that satisfies the requirement Flask==0.9-devdev-20120114 (from -r requirements.txt (line 2)) (from versions: )
No distributions matching the version for Flask==0.9-devdev-20120114 (from -r requirements.txt (line 2))
Storing complete log in /Users/dgrtwo/.pip/pip.log

sudo pip install --upgrade distribute

Don't have enough rep to comment, but sudo pip install --upgrade distribute borked my pip installation. Pip version 1.4.1. After running that command, pip freeze gives an AssertionError.
The fix for THAT is sudo pip install setuptools==7.0
The two solutions combined fixed the svn URL warning.

I encountered the same problem trying to create a django project and deploy it on heroku. I think the problem was related to having multiple copies of django. Deleting django located at
/usr/local/lib/python2.7/dist-packages/django
and the reinstalling seemed to solve the problem. I was able to create the requirements.txt without a warning.

Ron's idea borked my pip installation too, and MikeTwo's fix did not fix it.
I ended up removing pip and re-installing is, as found here (UzLA's comment). Remove package:
sudo apt-get remove --auto-remove python-pip
Download official pip installer:
wget https://bootstrap.pypa.io/get-pip.py
install it:
sudo python get-pip.py
pip freeze worked properly after this. It did give SNIMissingWarning and InsecurePlatformWarning, see the docs, but that's not the issue here.
Note: the source of this fix as has a 4th step, to set up a symlink from /usr/local/bin/pip to /usr/bin. This may not be necessary. Try stat /usr/local/bin/pip. That should report a regular file, size 200 bytes or so. You can less /usr/local/bin/pip to see what's in it. Then do echo $PATH to check if /usr/local/bin is in there. If it is, the symlink is not needed.

Related

How to add git source in requirements.txt

I would like to install a certain package from a private git repository. This is possible using pip install git+<REPO_LINK>. However, I would like to pip install -r requirements.txt all of my packages at the same time without having to specify which one comes from Pypi and private repo.
I have tried adding a configuration in ~/.config/pip/pip.conf
[global]
find-links =
git+<REPO_LINK>
but this happened when running pip install -r requirements.txt:
ERROR: Could not find a version that satisfies the requirement my-package==0.1
Thanks in advance.
I have found a solution for it at this doc.
pip install git+<REPO_LINK>#egg=<PACKAGE_NAME>
When I run pip freeze, the package I have just installed is printed like this:
git+<REPO_LINK>#egg=<PACKAGE_NAME>
Add it to your requirements.txt so pip install -r requirements.txt install this specific package so as public ones from Pypi.
:)

pip force reinstall in requirements.txt

I have a requirements.txt file in which I have some git+ references. I would like to always reinstall these as for some reason, even if I make changes and bump the version and push it to my github repo, pip says requirements already satisfied and doesn't install.
Here is part of my requirements.txt file:-
Django==1.10
git+https://github.com/myaccount/myrepo.git#master#egg=some_egg
I don't want to reinstall everything in the requirements.txt file. Only the git+ requirements.
I tried this:-
git+https://github.com/myaccount/myrepo.git#master#egg=some_egg --install-option="--upgrade --ignore-installed --force-reinstall"
But none of the above options worked.
The problem is that you haven't adviced pip what version do you have in git:
git+https://github.com/myaccount/myrepo.git#master#egg=some_egg
For VCS URLs pip doesn't look into the repo to find out the version, it only look at the URL:
git+https://github.com/myaccount/myrepo.git#master#egg=some_egg-version
example:
git+https://github.com/myaccount/myrepo.git#master#egg=package-1.0.8
When you push a new version to Github update your requirements.txt with new version(s) and run pip install -r requirements.txt -U.
Probably one option is to install the package in editable mode, like
Django==1.10
-e git+https://github.com/myaccount/myrepo.git#master#egg=some_egg
Pip developers stated in 2017 that they don't want you to be able to force reinstall in requirements.txt, although I don't think they explained why.
I use this:
pip install -r requirements.txt
And you can use some thing more like :
pip install -r requirements.txt --no-index --find-links
--no-index - Ignore package index (only looking at --find-links URLs instead).
-f, --find-links <URL> - If a URL or path to an html file, then parse for links to archives

How can I revert changes done to python packages?

I'm debugging an issue on a staging, and I've added a bunch of logging statements to a 3rd party package. Once I'm done with that, I'd like to get them back to their original state. In ruby, I could do a gem pristine lib_name and that would restore the lib to it's original source code.
It might be relevant to mention that I'm modifying code that was installed with sudo pip install some_pkg.
What's the usual way of reverting any changes done to a lib?
On Linux:
Just type the following command in a terminal (with pip, pip2 or pip3, accordingly to the Python version you're targetting):
sudo -H pip install --upgrade --force-reinstall some_pkg
On Windows:
Open an admin terminal, and run the following command (ditto):
pip install --upgrade --force-reinstall some_pkg
Try this
pip install -r requirements.txt --force --upgrade
I suppose you have one "requriemnt.txt" file which you want to revert back packages to:
#remove all currently installed packages
pip freeze > remove.txt
pip uninstall -r remove.txt
#re-insatll all packages
pip install -r requriement.txt
This ensures that you also remove all unwanted packages

What does " -r " do in pip install -r requirements.txt

I looked up how to install multiple packages from a requirements document using pip. The answers were mostly:
pip install -r requirements.txt
What does the -r do though? I can't find an answer for this and it isn't listed when I run pip help.
Instead of pip --help, look into pip install --help:
-r, --requirement Install from the given requirements
file. This option can be used multiple
times.
Also see these documentation paragraphs:
pip install
Requirements Files.
-r will search for requirement file.
pip install --help
will help you !!
May, 2022 Update:
If you run this command below without "-r":
pip install requirements.txt
You will get this error below:
ERROR: Could not find a version that satisfies the requirement requirements.txt (from versions: none)
HINT: You are attempting to install a package literally named "requirements.txt" (which cannot exist). Consider using the '-r' flag to install the packages listed in requirements.txt
ERROR: No matching distribution found for requirements.txt
Because "pip" tries to install the package "requirements.txt" instead of installing the packages listed in "requirements.txt". Of cource, the package "requirements.txt" doesn't exist in PyPI while for example, the packages "django" and "pillow" exist in PyPI:
pip install django
pip install pillow
So, to install the packages listed in "requirements.txt", you must need "-r";
pip install -r requirements.txt
You can check what "-r" means by running the command below:
pip install --help
-r, --requirement Install from the given requirements file. This option can be used multiple times.
In your case pip install -r requirements.txt will install the libraries listed in your requirements.txt file.
pip install requirements.txt
Above statement looks for a python package named requirements.txt. No such package exists. Your intention is that pip install opens the txt and reads the packages from there. The -r allows pip install to open requirements.txt and install the packages inside of it instead.

Upgrade python packages from requirements.txt using pip command

How do I upgrade all my python packages from requirements.txt file using pip command?
tried with below command
$ pip install --upgrade -r requirements.txt
Since, the python packages are suffixed with the version number (Django==1.5.1) they don't seem to upgrade. Is there any better approach than manually editing requirements.txt file?
EDIT
As Andy mentioned in his answer packages are pinned to a specific version, hence it is not possible to upgrade packages through pip command.
But, we can achieve this with pip-tools using the following command.
$ pip-review --auto
this will automatically upgrade all packages from requirements.txt (make sure to install pip-tools using pip install command).
I already answered this question here. Here's my solution:
Because there was no easy way for upgrading package by package, and updating the requirements.txt file, I wrote this pip-upgrader which also updates the versions in your requirements.txt file for the packages chosen (or all packages).
Installation
pip install pip-upgrader
Usage
Activate your virtualenv (important, because it will also install the new versions of upgraded packages in current virtualenv).
cd into your project directory, then run:
pip-upgrade
Advanced usage
If the requirements are placed in a non-standard location, send them as arguments:
pip-upgrade path/to/requirements.txt
If you already know what package you want to upgrade, simply send them as arguments:
pip-upgrade -p django -p celery -p dateutil
If you need to upgrade to pre-release / post-release version, add --prerelease argument to your command.
Full disclosure: I wrote this package.
you can try:
pip install --upgrade --force-reinstall -r requirements.txt
You can also ignore installed package and install the new one :
pip install --ignore-installed -r requirements.txt
No. Your requirements file has been pinned to specific versions. If your requirements are set to that version, you should not be trying to upgrade beyond those versions. If you need to upgrade, then you need to switch to unpinned versions in your requirements file.
Example:
lxml>=2.2.0
This would upgrade lxml to any version newer than 2.2.0
lxml>=2.2.0,<2.3.0
This would upgrade lxml to the most recent version between 2.2.0 and 2.3.0.
I suggest freezing all of your dependencies in order to have predictable builds.
When doing that, you can update all dependencies at once like this:
sed -i '' 's/[~=]=/>=/' requirements.txt
pip install -U -r requirements.txt
pip freeze | sed 's/==/~=/' > requirements.txt
Having done the above, test your project with the new set of packages and eventually commit the requirements.txt file to the repository while still allowing for installing hot-fixes.
Another solution is to use the upgrade-requirements package
pip install upgrade-requirements
And then run :
upgrade-requirements
It will upgrade all the packages that are not at their latest versions, and also create an updated requirements.txt at the end.
Fixing dependencies to a specific version is the recommended practice.
Here's another solution using pur to keep the dependencies fresh!
Give pur your requirements.txt file and it will auto update all your high-level packages to the latest versions, keeping your original formatting and comments in-place.
For example, running pur on the example requirements.txt updates the packages to the currently available latest versions:
$ pur -r requirements.txt
Updated flask: 0.9 -> 0.10.1
Updated sqlalchemy: 0.9.10 -> 1.0.12
Updated alembic: 0.8.4 -> 0.8.6
All requirements up-to-date.
As pur never modifies your environment or installed packages, it's extremely fast and you can safely run it without fear of corrupting your local virtual environment. Pur separates updating your requirements.txt file from installing the updates. So you can use pur, then install the updates in separate steps.
I've just had to do the same... used this small one-liner to do the job:
packages=$(cat requirements.txt | sed 's/==.*//g'); echo $packages | xargs pip3 install -U; freeze=$(pip3 freeze); for p in $(echo $packages); do echo $freeze | grep -E "^${p}==" >> requirements.new; done
which:
packages=$(cat requirements.txt | sed 's/==.*//g') creates a list of the current packages names in requirements.txt (removing the version).
echo $packages | xargs pip3 install -U then passes all of the packages as arguments to pip3 to upgrade.
freeze=$(pip3 freeze); Gets all of the current package versions in the format required for requirements.txt
for p in $(echo $packages) then iterates through the package names
echo $freeze | grep -E "^${p}==" >> requirements.new gets the package version line from the pip freeze output which matches the package and writes to new requirements.txt
This has the added benefit of preserving the ordering of the original requirements.txt. :)
Hope this helps!
The second answer is the most useful but what I wanted to do is lock some packages while having others at the latest version (e.g. youtube-dl).
An example requirements.txt would look like this (~ means compatible):
Pillow==6.2.2
requests~=2.22.0
youtube_dl
Then in the terminal, use the command pip install --upgrade -r requirements.txt
This ensures that Pillow will stay at 6.2.2, requests will be upgraded to the latest 2.22.x (if available), and the latest version of youtube-dl will be installed if not already.
Since I couldn't do that using bash, I wrote a python module to create a new requirements file with no versions and use it:
data = open('requirements-prod.pip', 'r')
data2 = open('requirements-prod-no-version.pip', 'w')
for line in data.readlines():
new_line = line[:line.index('==')]
data2.write(new_line + '\n')
data2.flush()
Then install the libs from the new file pip install -U -r requirements-prod-no-version.pip
Finally freeze the versions to the original file pip freeze > requirements-prod.pip
More robust solution is IMO to use a dependency management such as poetry, https://python-poetry.org which comes with an exhaustive dependency resolver.
I guess the simplest solution is creating the requirements.txt with:
pip freeze | sed 's/==/>=/' > requirements.txt
You can use below command on Linux and Mac:
cat requirements.txt | cut -f1 -d= | xargs pip install -U
1) To upgrade pip installed files from reqs.txt
add the >= in replacement of ==
this will tell pip to install lib greater than or equal to the version you are requesting, here by installing the most to-date version of requested library
1.a) **My answer for thread ** By adding py -m pip install -r reqs.txt to a daily restart... or something of the nature you can update your installed libs.
Summed up by Andy Perfectly
-My reason For entering this thread was to find information on how to update virtual env base pip (usually 10.0.03 for me??)
in-hopes of satisfying an issue of which have I was able to derive one of two solutions
A. creation of venv || B. Installation of Required libs
Thanks to Andy I have satisfied need B
By adding pip >= requested version in reqs.txt
upon instantiation of new virtual-Environment || re-instantiation of previous Venv
py -m venv devenv
to setup new dev env
devenv\scripts\activate.bat
to activate dev env
python -m pip install -r requirenments.txt
to install base libs
yeilds output
Collecting pip >= 20.0.2 (from -r requirenments.txt (line 1))
Using cached >https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
Successfully installed pip-20.0.2
Sorry for the Brain Dump, Hopes this helps someone :)
🤳 Austin 👨‍🎤🚀🥊
If you install anything in your django project and after installation you want to update your requirement file this command can update you requirement.txt file
pip freeze > requirements.txt
if your requirement file not exist in you project you can use this command for make new requirement.txt file
pip freeze > requirements.txt
With pip-tools you have a basic requirements.in with desired dependencies and a requirements.txt file with pinned versions. pip-tools then generates the pinned versions automatically, which makes handling the whole process including upgrading your dependencies a lot easier.
# requirements.in
django
and the autogenerated requirements.txt (to pin all dependencies)
$ pip-compile requirements.in
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
asgiref==3.2.3
# via django
django==3.0.3
# via -r requirements.in
pytz==2019.3
# via django
sqlparse==0.3.0
# via django
If you use that workflow, which I can highly recommend, it's
pip-compile --upgrade
which generates the requirements.txt with the latest versions.
I edit the requirements.txt as below and run $sh ./requirements.txt
pip install -U amqp;
pip install -U appdirs;
pip install -U arrow;
pip install -U Babel;
pip install -U billiard;
pip install -U celery;
pip install -U Django;
pip install -U django-cors-headers;
pip install -U django-crispy-forms;
pip install -U django-filter;
pip install -U django-markdown-deux;
pip install -U django-pagedown;
pip install -U django-timezone-field;
pip install -U djangorestframework;
pip install -U fcm-django;
pip install -U flower;
pip install -U gunicorn;
pip install -U kombu;
pip install -U Markdown;
pip install -U markdown2;
pip install -U packaging;

Categories