I tried to install the Twilio module:
sudo -H pip install twilio
And I got this error:
Installing collected packages: pyOpenSSL
Found existing installation: pyOpenSSL 0.13.1
Cannot uninstall 'pyOpenSSL'. It is a distutils installed project and
thus we cannot accurately determine which files belong to it which
would lead to only a partial uninstall.
Anyone know how to uninstall pyOpenSSL?
This error means that this package's metadata doesn't include a list of files that belong to it. Most probably, you have installed this package via your OS' package manager, so you need to use that rather than pip to update or remove it, too.
See e.g. Upgrading to pip 10: It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall. · Issue #5247 · pypa/pip for one such example where the package was installed with apt.
Alternatively, depending on your needs, it may be more productive to not use your system Python and/or its global environment but create a private Python installation and/or environment. There are many options here including virtualenv, venv, pyenv, pipenv and installing Python from source into
/usr/local or $HOME/$HOME/.local (or /opt/<whatever>).
Finally, I must comment on the often-suggested (e.g. at pip 10 and apt: how to avoid "Cannot uninstall X" errors for distutils packages) --ignore-installed pip switch.
It may work (potentially for a long enough time for your business needs), but may just as well break things on the system in unpredictable ways. One thing is sure: it makes the system's configuration unsupported and thus unmaintainable -- because you have essentially overwritten files from your distribution with some other arbitrary stuff. E.g.:
If the new files are binary incompatible with the old ones, other software from the distribution built to link against the originals will segfault or otherwise malfunction.
If the new version has a different set of files, you'll end up with a mix of old and new files which may break dependent software as well as the package itself.
If you change the package with your OS' package manager later, it will overwrite pip-installed files, with similarly unpredictable results.
If there are things like configuration files, differences in them between the versions can also lead to all sorts of breakage.
I had the same error and was able to resolve using the following steps:
pip install --ignore-installed pyOpenSSL
This will install the package with latest version and then if you try to install,
pip install twilio
It will work.
Generally, for similar errors, use this format:
pip install --ignore-installed [package name]==[package version]
I just had this error and the only way I was able to resolve it was by manually deleting the offending directory from site-packages.
After doing this you may need to reinstall the packages with --force-reinstall.
Reading the above comments, I understood that package a was installed with conda and the new package b that I was trying to install using pip was causing problems. I was lucky that package b had conda support so using conda to install package b solved the problem.
In my case, I was installing a package from internal git using the following command:
python -m pip install package.whl --force
I was doing this because I didn't want to explicitly uninstall the previous version and just replace it with a newer version. But what it also does is install all the dependencies again. I was getting the error in one of those packages. Removing --force fixed the problem.
I want to add, having --ignore-installed also worked for me. And removing --force is essentially doing the same thing in my case.
Related
I tried to install the Twilio module:
sudo -H pip install twilio
And I got this error:
Installing collected packages: pyOpenSSL
Found existing installation: pyOpenSSL 0.13.1
Cannot uninstall 'pyOpenSSL'. It is a distutils installed project and
thus we cannot accurately determine which files belong to it which
would lead to only a partial uninstall.
Anyone know how to uninstall pyOpenSSL?
This error means that this package's metadata doesn't include a list of files that belong to it. Most probably, you have installed this package via your OS' package manager, so you need to use that rather than pip to update or remove it, too.
See e.g. Upgrading to pip 10: It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall. · Issue #5247 · pypa/pip for one such example where the package was installed with apt.
Alternatively, depending on your needs, it may be more productive to not use your system Python and/or its global environment but create a private Python installation and/or environment. There are many options here including virtualenv, venv, pyenv, pipenv and installing Python from source into
/usr/local or $HOME/$HOME/.local (or /opt/<whatever>).
Finally, I must comment on the often-suggested (e.g. at pip 10 and apt: how to avoid "Cannot uninstall X" errors for distutils packages) --ignore-installed pip switch.
It may work (potentially for a long enough time for your business needs), but may just as well break things on the system in unpredictable ways. One thing is sure: it makes the system's configuration unsupported and thus unmaintainable -- because you have essentially overwritten files from your distribution with some other arbitrary stuff. E.g.:
If the new files are binary incompatible with the old ones, other software from the distribution built to link against the originals will segfault or otherwise malfunction.
If the new version has a different set of files, you'll end up with a mix of old and new files which may break dependent software as well as the package itself.
If you change the package with your OS' package manager later, it will overwrite pip-installed files, with similarly unpredictable results.
If there are things like configuration files, differences in them between the versions can also lead to all sorts of breakage.
I had the same error and was able to resolve using the following steps:
pip install --ignore-installed pyOpenSSL
This will install the package with latest version and then if you try to install,
pip install twilio
It will work.
Generally, for similar errors, use this format:
pip install --ignore-installed [package name]==[package version]
I just had this error and the only way I was able to resolve it was by manually deleting the offending directory from site-packages.
After doing this you may need to reinstall the packages with --force-reinstall.
Reading the above comments, I understood that package a was installed with conda and the new package b that I was trying to install using pip was causing problems. I was lucky that package b had conda support so using conda to install package b solved the problem.
In my case, I was installing a package from internal git using the following command:
python -m pip install package.whl --force
I was doing this because I didn't want to explicitly uninstall the previous version and just replace it with a newer version. But what it also does is install all the dependencies again. I was getting the error in one of those packages. Removing --force fixed the problem.
I want to add, having --ignore-installed also worked for me. And removing --force is essentially doing the same thing in my case.
Is it possible to re-check the dependencies of packages installed with pip? That is, suppose we have a working environment. Then, one of the packages changes (gets upgraded, etc). Is there a command one can run to make to make sure that the dependency tree is still sound and does not have conflicts?
Nowadays python -m pip check should do the trick.
Seems to have been added as early as pip 9.0.0 released on 2016-11-02.
It's not part of pip, but there is a tool you can use called pip-conflict-checker. Just install it through pip and run pipconflictchecker to get a dump of all the conflicts. pipdeptree could also help here.
You might also be interested in reading this article about dealing with pip dependency issues. The article also discusses the two tools I mentioned above along with strategies to fix broken dependencies.
In recent pip versions using pip install -r requirements.txt will fail if you have any conflict in your dependencies specified in requirements.txt.
When I install some python packages in Fedora, there're two ways:
use dnf install python-package
use pip install package
I notice even I use dnf update to make my Fedora the newest,
when I use pip, it still tell me something like
pip is a old version, please use pip update
I guess the dnf package management is different with python-pip package management.
So which one is more recommended to install python packages ?
Quoted from Gentoo Wiki:
It is important to understand that packages installed using pip will not be tracked by Portage. This is the case for installing any package through means other than the emerge command. Possible conflicts can be created when installing a Python package that is available in the Portage tree, then installing the same package using pip.
Decide which package manager will work best for the use case: either use emerge or pip for Python packages, but not both. Sometimes a certain Python packages will not be available in the Portage tree, in these cases the only option is to use pip. Be wise and make good choices!
This is true for almost any nowadays package managers. If you are using packages or certain package versions that only exists in pip, use it but don't try to install that from dnf. Doing this will not only cause file collisions but also will (most possibly) break the package manager's knowledge of the system, which usually leads to major package management issues.
Other solution would be using pip in user mode, without root permissions, which will install relevant things into your home directory.
So again, it's both okay to use pip or dnf, but just don't mix these two package managers together.
I am trying to install the 64-bit version of NTLK, which comes in a .whl file, in a different directory than the standard python34/Lib folder. I am using Windows 10 64-bit and Python 3.4 64-bit.
I first tried using the instructions in this question (which worked for other modules).
The command I typed into CMD was:
py -m pip install --install-option="--prefix=$PATH_NAME" nltk-3.0.4-py2.py3-none-any.whl
It promptly gave me the following error:
UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
It appears that I can't install WHL files using the --install-option. Is there an alternate way I can install the .whl package in a non default directory?
Edit: I marked this as solved because the proposed solution allows me to do what I need in my own use case. However, it doesn't completely answer the question due to inherent limitations in using --root to choose an alternate directory. There is technically no correct solution to this problem, see the answer's comments for details.
Edit - March 3, 2017: It looks like this issue has been resolved in version 8.0 of PIP with the addition of the --prefix parameter. I've changed the accepted answer accordingly.
You can use the --prefix option of pip install, available since version 8:
--prefix
Installation prefix where lib, bin and other top-level folders are placed
Note that pip uninstall does not have the --prefix option, so there is no obvious way to uninstall packages installed this way. As a workaround, set PYTHONUSERBASE to the prefix directory, e.g.:
PYTHONUSERBASE=prefix-dir python3 -m pip uninstall package-name
Why it happens
When running pip install from source, it invokes a build process, which runs the setup.py script and passes to it the --install-option you pass in.
Installing wheels however does not invoke this build process, and no decision has been made about supporting these use cases, as of yet (see the ongoing discussion).
Possible solution
However, pip install does currently support installing to custom locations with the options --user and --root, which may achieve what you are looking for.
Caveats
As mentioned in the comments, there seems to be an issue with detecting whether the package is already installed when using --root, and the workaround could be using --upgrade or --ignore-installed options.
Additionally, using --root will install the module to user_defined_path/python34/Lib/site-packages/. This makes this option useful for installing the library on a different drive or a non-default python installation, but does not allow installing to a specific folder within a specific directory.
See another way of solving your problem would be by using 7-zip and unzipping the whl file which inside the unzipped directory will give you a proper folder of the python module which you can then copy and paste wherever you wish
Wondering if anyone knows a workaround to force pip to either completely skip hash checks or ignore bad sums when installing from a download cache? Install cmd is:
pip.exe install --target=C:\WHERE_I_WANT_INSTALLED --download-cache=C:\MY_DL_CACHE mitmproxy
Mitmproxy requires a specific version of pillow, and in that specific version there just happens to be a defined C function whos signature collides with another function in an include within Mingw x86_64. I'm not changing out my toolchain, as anyone who uses mingw on windows knows, it's a disgustingly painful process to find and keep a stable version.
Anyway, I've posted the question as a bug report on pips github but I thought I'd pose the question here. Thanks in advance.
Well, I found the answer in the very last place I would ever think to look: the documentation.
So basically you run a few commands to have pip download everything that is required for what you're trying to install. In this case, its was mitmproxy. So first I grabbed the requirements.txt file for mitmproxy, and dropped it into a dir. Commands to download packages were:
pip install --download C:\MY_SECRET_PATH\mitm\dl-cache six
pip install --download C:\MY_SECRET_PATH\mitm\dl-cache mock
pip install --download C:\MY_SECRET_PATH\mitm\dl-cache itsdangerous
pip install --download C:\MY_SECRET_PATH\mitm\dl-cache cryptography
pip install --download C:\MY_SECRET_PATH\mitm\dl-cache mitmproxy
Now, everything required for mitm-proxy is stored in the provided path. We then supply this path and a couple of other flags to the command for installing what we're after, again mitmproxy. To make things more interesting, I'm installing all of this stuff in a custom dir. So that command is as follows:
pip.exe install mitmproxy --no-index --target=C:\MY_SECRET_PATH\mitm --find-links=C:\MY_SECRET_PATH\mitm
So we're basically telling pip to install the selected package and all its deps offline, not checking pypy and therefore skipping hash checks. You're then obviously free to modify the sources of the packages you've downloaded, as I have.