Pip installs to wrong directory - python

I'm on OS X and my Pip installs to
/Library/Python/2.7/site-packages
I would like my pip to install to:
/usr/local/lib/python2.7/site-packages
How could I achieve this? I haven't found a way yet

pip has an option for target directory --target, when installing package use
pip install --target=/usr/local/lib/python2.7/site-packages package_name
to install to your target directory.
if target option not available, check pip version & for possible
upgrade or as mentioned in comments the error may be related to OSX/Homebrew install, check here for details.

Related

How can pip know a package's last version?

I use pip to manage my packages, but how can I know a package's newest version?
I use the
pip install --upgrade eventlet
find the result the version did not change. still is eventlet (0.21.0).
But in the GitHub, you see the doc the newest version is v0.22.1.
If a package is not updated on pypi, you cannot pip install packagename to get the latest version. If you absolutely want the latest version you can install it directly from git
git clone <git URL of library>
cd into the directory and install the package:
sudo python setup.py install
if you want to get the list of all the modules that can be updated i.e. the modules with updated available you can use:
pip list --outdated
This will give you the output like
....
ipython (6.2.1) - Latest: 6.3.1 [wheel]
....
allowing you to chose the packages you want to update

How to change the install path for PIP

I got my pip install directory in
/Library/Python/2.7/site-packages
Somehow, after I install the wordbatch library, my pip install path changes to
/usr/local/lib/python2.7/site-packages
Does anyone know how to change the pip install path?
One idea is you can just install it anywere. Then move it to the correct directory. This should fix the problem, if you want it to install there from the start. Then i don't know.
You can see help of pip install in bash like pip install --help.
Current task you need use parameters --target /usr/local/lib/python2.7/site-packages.

pip install error: "Unknown archive format: .whl"

I'm new to virtualenv (on windows). I'm trying to use pip (1.5) install a local wheel file, but it is failing.
The command is:
pip install --no-index -f C:/Users/<User>/Download openpyxl
In the pip.log, I can see where it finds the correct file, but then doesn't try to install it:
Skipping link file:///C:/Users/<User>/Download/openpyxl-1.7.0-py2.py3-none-any.whl; unknown archive format: .whl
I have wheel (version 0.22) install globally as well as in the virtual environment. Any idea how I can get .whl to be a recognized format?
It appears wheel support is disabled.
Make sure that you have setuptools version 0.8 or newer installed, and that the use-wheel option is not set to false in $HOME/.pip/pip.conf.
Upgrading setuptools is easy enough if pip is already working:
pip install --upgrade setuptools
but note that older virtualenv versions can depend on older setuptools versions; you'll need to make sure that virtualenv is also up to date.
I have bumped into the same problem with wheel when downloaded requirements with:
pip install --download /pip_mirror six django_debug_toolbar
dir2pi /pip_mirror/
and tried to install them with:
pip install six-1.7.3-py2.py3-none-any.whl
Even though there is no any config at $HOME/.pip/pip.conf and
$ easy_install --version
setuptools 5.4.1
I still get:
unknown archive format: .whl
I have managed to avoid the problem by adding --no-use-wheel like this, so got only tar.gz files (instead of .whl)
pip install --no-use-wheel --download /pip_mirror six django_debug_toolbar
dir2pi /pip_mirror/
After this pip install --index-url=file:///pip_mirror/simple/ six went without any problems

Why can't pip uninstall pysqlite?

I'm trying to remove pysqlite from my system using pip.
What I get doing so makes no sense:
$ pip uninstall pysqlite
The command worked, but watch this:
$ pip freeze
[...]
pysqlite==1.0.1
Let's try again
$ pip uninstall pysqlite
Can't uninstall 'pysqlite'. No files were found to uninstall.
Nop, seems removed but still show up in pip freeze
Now comes the fun
$ pip install pysqlite
Requirement already satisfied (use --upgrade to upgrade): pysqlite in /usr/lib/python2.6/dist-packages
Cleaning up...
Fair enough:
$ pip install -U pysqlite
[...]
error: command 'gcc' failed with exit status 1
[...]
Can't roll back pysqlite; was not uninstalled
[...]
I just don't get it. Why can't pip uninstall pysqlite?
Go to your /usr/lib/python2.6/site-packages/pysqlite*.egg/ (or anywhere else you store your eggs in your python path) and look for the installed-files.txt file.
If it does not exists, pip will not be able to uninstall it, if it does, you remove all the files within and you're rid of pysqlite. And as Martijn suggests, you should also check if you did not install your package with another package manager.
If you don't have the installed-files.txt, and your package has not been installed through a third-part package manager, you shall look up where your egg is, and remove it from the python path. Usually, eggs also write files in the directory where they lay, so you should look for a pysqlite/ directory in the directory where lays pysqlite.egg.
For the record, I was able to upgrade a package I was having this issue with by using the --ignore-installed flag, e.g.
pip install python-dateutil --upgrade --ignore-installed
Just give another way.
I pip-installed ykdl which requires m3u8 and iso8601.
Then I wanted to uninstall them all, pip uninstall ykdl iso8601 m3u8.The ykdl and iso8601 were gone, but I couldn't uninstall the m3u8.And I saw it in pip list. I puzzled too.
Finally.When I tried to import m3u8, it failed and said 'needs iso8601'. So i installed iso8601, then uninstalled m3u8,iso8601 one by one. It worked
=====
It was on ubuntu. But on my Windows 10, I uninstalled iso8601 m3u8 ykdl step by step successfully. Exciting!

Installing specific package version with pip

I am trying to install version 1.2.2 of MySQL_python, using a fresh virtualenv created with the --no-site-packages option. The current version shown in PyPi is 1.2.3. Is there a way to install the older version? I have tried:
pip install MySQL_python==1.2.2
However, when installed, it still shows MySQL_python-1.2.3-py2.6.egg-info in the site packages. Is this a problem specific to this package, or am I doing something wrong?
TL;DR:
Update as of 2022-12-28:
pip install --force-reinstall -v
For example: pip install --force-reinstall -v "MySQL_python==1.2.2"
What these options mean:
--force-reinstall is an option to reinstall all packages even if they are already up-to-date.
-v is for verbose. You can combine for even more verbosity (i.e. -vv) up to 3 times (e.g. --force-reinstall -vvv).
Thanks to #Peter for highlighting this (and it seems that the context of the question has broadened given the time when the question was first asked!), the documentation for Python discusses a caveat with using -I, in that it can break your installation if it was installed with a different package manager or if if your package is/was a different version.
Original answer:
pip install -Iv (i.e. pip install -Iv MySQL_python==1.2.2)
What these options mean:
-I stands for --ignore-installed which will ignore the installed packages, overwriting them.
-v is for verbose. You can combine for even more verbosity (i.e. -vv) up to 3 times (e.g. -Ivvv).
For more information, see pip install --help
First, I see two issues with what you're trying to do. Since you already have an installed version, you should either uninstall the current existing driver or use pip install -I MySQL_python==1.2.2
However, you'll soon find out that this doesn't work. If you look at pip's installation log, or if you do a pip install -Iv MySQL_python==1.2.2 you'll find that the PyPI URL link does not work for MySQL_python v1.2.2. You can verify this here: http://pypi.python.org/pypi/MySQL-python/1.2.2
The download link 404s and the fallback URL links are re-directing infinitely due to sourceforge.net's recent upgrade and PyPI's stale URL.
So to properly install the driver, you can follow these steps:
pip uninstall MySQL_python
pip install -Iv http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz/download
You can even use a version range with pip install command. Something like this:
pip install 'stevedore>=1.3.0,<1.4.0'
And if the package is already installed and you want to downgrade it add --force-reinstall like this:
pip install 'stevedore>=1.3.0,<1.4.0' --force-reinstall
One way, as suggested in this post, is to mention version in pip as:
pip install -Iv MySQL_python==1.2.2
i.e. Use == and mention the version number to install only that version. -I, --ignore-installed ignores already installed packages.
To install a specific python package version whether it is the first time, an upgrade or a downgrade use:
pip install --force-reinstall MySQL_python==1.2.4
MySQL_python version 1.2.2 is not available so I used a different version. To view all available package versions from an index exclude the version:
pip install MySQL_python==
I believe that if you already have a package it installed, pip will not overwrite it with another version. Use -I to ignore previous versions.
Sometimes, the previously installed version is cached.
~$ pip install pillow==5.2.0
It returns the followings:
Requirement already satisfied: pillow==5.2.0 in /home/ubuntu/anaconda3/lib/python3.6/site-packages (5.2.0)
We can use --no-cache-dir together with -I to overwrite this
~$ pip install --no-cache-dir -I pillow==5.2.0
Since this appeared to be a breaking change introduced in version 10 of pip, I downgraded to a compatible version:
pip install 'pip<10'
This command tells pip to install a version of the module lower than version 10. Do this in a virutalenv so you don't screw up your site installation of Python.
This below command worked for me
Python version - 2.7
package - python-jenkins
command - $ pip install 'python-jenkins>=1.1.1'
I recently ran into an issue when using pip's -I flag that I wanted to document somewhere:
-I will not uninstall the existing package before proceeding; it will just install it on top of the old one. This means that any files that should be deleted between versions will instead be left in place. This can cause weird behavior if those files share names with other installed modules.
For example, let's say there's a package named package. In one of packages files, they use import datetime. Now, in package#2.0.0, this points to the standard library datetime module, but in package#3.0.0, they added a local datetime.py as a replacement for the standard library version (for whatever reason).
Now lets say I run pip install package==3.0.0, but then later realize that I actually wanted version 2.0.0. If I now run pip install -I package==2.0.0, the old datetime.py file will not be removed, so any calls to import datetime will import the wrong module.
In my case, this manifested with strange syntax errors because the newer version of the package added a file that was only compatible with Python 3, and when I downgraded package versions to support Python 2, I continued importing the Python-3-only module.
Based on this, I would argue that uninstalling the old package is always preferable to using -I when updating installed package versions.
There are 2 ways you may install any package with version:-
A). pip install -Iv package-name == version
B). pip install -v package-name == version
For A
Here, if you're using -I option while installing(when you don't know if the package is already installed) (like 'pip install -Iv pyreadline == 2.* 'or something), you would be installing a new separate package with the same existing package having some different version.
For B
At first, you may want to check for no broken requirements.
pip check
2.and then see what's already installed by
pip list
3.if the list of the packages contain any package that you wish to install with specific version then the better option is to uninstall the package of this version first, by
pip uninstall package-name
4.And now you can go ahead to reinstall the same package with a specific version, by
pip install -v package-name==version
e.g. pip install -v pyreadline == 2.*
If you want to update to latest version and you don't know what is the latest version you can type.
pip install MySQL_python --upgrade
This will update the MySQL_python for latest version available, you can use for any other package version.
dependency packaging has had a new release, wherein it has dropped LegacyVersion from its codebase
The quick solution might be pin packaging==21.3

Categories

Resources