Is it possible? When installing pip, install the python packages inside my $HOME folder. (for example, I want to install mercurial, using pip, but inside $HOME instead of /usr/local)
I’m with a mac machine and just thought about this possibility, instead of “polluting” my /usr/local, I would use my $HOME instead.
PEP370 is exactly about this. Is just creating a ˜/.local and do a pip install package enough to make these packages to be installed only at my $HOME folder?
请注意,以上内容适用于Python 2.6。一直有一些争议的关于什么是PEP370风格的Mac OS X上的相应目录位置Python的核心开发者user安装。在Python 2.7和3.2中,Mac OS X上的位置从更改$HOME/.local为$HOME/Library/Python。这可能会在将来的版本中更改。但是,目前,在2.7(和3.2,如果hgPython 3支持的话)上,上述位置将是$HOME/Library/Python/x.y/bin/hg和$HOME/Library/Python/x.y/lib/python/site-packages。
While you can use a virtualenv, you don’t need to. The trick is passing the PEP370 --user argument to the setup.py script. With the latest version of pip, one way to do it is:
pip install --user mercurial
This should result in the hg script being installed in $HOME/.local/bin/hg and the rest of the hg package in $HOME/.local/lib/pythonx.y/site-packages/.
Note, that the above is true for Python 2.6. There has been a bit of controversy among the Python core developers about what is the appropriate directory location on Mac OS X for PEP370-style user installations. In Python 2.7 and 3.2, the location on Mac OS X was changed from $HOME/.local to $HOME/Library/Python. This might change in a future release. But, for now, on 2.7 (and 3.2, if hg were supported on Python 3), the above locations will be $HOME/Library/Python/x.y/bin/hg and $HOME/Library/Python/x.y/lib/python/site-packages.
You could then also alter ~/.(login|profile|bash_profile), whichever is right for your shell to add ~/bin to your PATH and then that pip|python|easy_install would be the one used by default.
You can specify the -t option (--target) to specify the destination directory. See pip install --help for detailed information. This is the command you need:
pip install -t path_to_your_home package-name
for example, for installing say mxnet, in my $HOME directory, I type:
This module makes available standard errno system symbols. The value of each symbol is the corresponding integer value. The names and descriptions are borrowed from linux/include/errno.h, which should be pretty all-inclusive.
Error code 1 is defined in errno.h and means Operation not permitted.
Here’s a little guide explaining a little bit how I usually install new packages on Python + Windows. It seems you’re using Windows paths, so this answer will stick to that particular SO:
I never use a system-wide Python installation. I only use virtualenvs, and usually I try to have the latest version of 2.x & 3.x.
My first attempt is always doing pip install package_i_want in some of my Visual Studio command prompts. What Visual Studio command prompt? Well, ideally the Visual Studio which matches the one which was used to build Python. For instance, let’s say your Python installation says Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32. The version of Visual Studio used to compile Python can be found here, so v1500 means I’d be using vs2008 x64 command prompt
If the previous step failed for some reason I just try using easy_install package_i_want
If the previous step failed for some reason I go to gohlke website and I check whether my package is available over there. If it’s so, I’m lucky, I just download it into my virtualenv and then I just go to that location using a command prompt and I do pip install package_i_want.whl
If the previous step didn’t succeed I’ll just try to build the wheel myself and once it’s generated I’ll try to install it with pip install package_i_want.whl
Now, if we focus in your specific problem, where you’re having a hard time installing the unroll package. It seems the fastest way to install it is doing something like this:
git clone https://github.com/Zulko/unroll
cd unroll && python setup.py bdist_wheel
Copy the generated unroll-0.1.0-py2-none-any.whl file from the created dist folder into your virtualenv.
pip install unroll-0.1.0-py2-none-any.whl
That way it will install without any problems. To check it really works, just login into the Python installation and try import unroll, it shouldn’t complain.
One last note: This method works almost 99% of the time, and sometimes you’ll find some pip packages which are specific to Unix or Mac OS X, in that case, when that happens I’m afraid the best way to get a Windows version is either posting some issues to the main developers or having some fun by yourself porting to Windows (typically a few hours if you’re not lucky) :)
Download and install the Microsoft Visual C++ Compiler for Python 2.7 from https://www.microsoft.com/en-in/download/details.aspx?id=44266 – this package contains the compiler and set of system headers necessary for producing binary wheels for Python 2.7 packages.
Open a command prompt in elevated mode (run as administrator)
Firstly do pip install ez_setup
Then do pip install unroll (It will start installing numpy, music21, decorator, imageio, tqdm, moviepy, unroll) # Please be patient for music21 installation
pyparsing 2.2 was already installed and my requirements.txt was trying to install pyparsing 2.0.1 which throw this error
Context: I was using virtualenv, and it seems the 2.2 came from my global OS Python site-packages, but even with --no-site-packages flag (now by default in last virtualenv) the 2.2 was still present. Surely because I installed Python from their website and it added Python libraries to my $PATH.
Maybe a pip install --ignore-installed would have worked.
Solution: as I needed to move forwards, I just removed the pyparsing==2.0.1 from my requirements.txt.
I tried all of the above with no success. I then updated my Python version from 2.7.10 to 2.7.13, and it resolved the problems that I was experiencing.
pip3 install –upgrade setuptools
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
******To avoid this problem you can invoke Python with ‘-m pip’ instead of running pip directly.******
I faced the same problem with the same error message but on Ubuntu 16.04 LTS (Xenial Xerus) instead:
Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-install-w71uo1rg/poster/
I tested all the solutions provided above and none of them worked for me. I read the full TraceBack and found out I had to create the virtual environment with Python version 2.7 instead (the default one uses Python 3.5 instead):
virtualenv --python=/usr/bin/python2.7 my_venv
Once I activated it, I run pip install unirest successfully.
Had the same problem on my Win10 PC with different packages and tried everything mentioned so far.
Finally solved it by disabling Comodo Auto-Containment.
Since nobody has mentioned it yet, I hope it helps someone.
回答 22
我遇到了同样的问题,可以通过以下操作解决。
Windows Python需要通过SDK安装的Visual C ++库来构建代码,例如通过setuptools.extension.Extension或numpy.distutils.core.Extension。例如,在Windows中使用Python构建f2py模块需要安装上述Visual C ++ SDK。在Linux和Mac上,C ++库随编译器一起安装。
I had the same problem and was able to fix by doing the following.
Windows Python needs Visual C++ libraries installed via the SDK to build code, such as via setuptools.extension.Extension or numpy.distutils.core.Extension. For example, building f2py modules in Windows with Python requires Visual C++ SDK as installed above. On Linux and Mac, the C++ libraries are installed with the compiler.
I activated a virtualenv which has pip installed. I did
pip3 install Django==1.8
and Django successfully downloaded. Now, I want to open up the Django folder. Where is the folder located? Normally it would be in “downloads” but I’m not sure where it would be if I installed it using pip in a virtualenv.
Update: This feature is introduced in pip 10.0.0b1. On Ubuntu 18.04, pip or pip3 installed with sudo apt install python-pip or sudo apt install python3-pip is 9.0.1 which doesn’t have this feature. Check https://github.com/pypa/pip/issues/5599 for suitable ways of upgrading pip or pip3.
By default, on Linux, Pip installs packages to /usr/local/lib/python2.7/dist-packages.
Using virtualenv or –user during install will change this default location. If you use pip show make sure you are using the right user or else pip may not see the packages you are referencing.
回答 4
在Python解释器或脚本中,您可以执行
import site
site.getsitepackages()# list of global package locations
和
site.getusersitepackages()#string for user-specific package location
This will work for all Mac, Windows, and Linux systems.
To get the list of all pip packages in the requirements.txt file (Note: This will overwrite requirements.txt if exist else will create the new one, also if you don’t want to replace old requirements.txt then give different file name in the all following command in place requirements.txt).
pip freeze > requirements.txt
Now to remove one by one
pip uninstall -r requirements.txt
If we want to remove all at once then
pip uninstall -r requirements.txt -y
If you’re working on an existing project that has a requirements.txt file and your environment has diverged, simply replace requirements.txt from the above examples with toberemoved.txt. Then, once you have gone through the steps above, you can use the requirements.txt to update your now clean environment.
And For single command without creating any file (As @joeb suggested).
I wanted to elevate this answer out of a comment section because it’s one of the most elegant solutions in the thread. Full credit for this answer goes to @joeb.
pip uninstall -y -r <(pip freeze)
This worked great for me for the use case of clearing my user packages folder outside the context of a virtualenv which many of the above answers don’t handle.
Edit: Anyone know how to make this command work in a Makefile?
Bonus: A bash alias
I add this to my bash profile for convenience:
alias pipuninstallall="pip uninstall -y -r <(pip freeze)"
Then run:
pipuninstallall
Alternative for pipenv
If you happen to be using pipenv you can just run:
Just a warning that this isn’t completely solid as you may run into issues such as ‘File not found’ but it may work in some cases nonetheless
EDIT: For clarity: unins is an arbitrary file which has data written out to it when this command executes: pip freeze > unins
That file that it written in turn is then used to uninstall the aforementioned packages with implied consent/prior approval via pip uninstall -y -r unins
(adding this as an answer, because I do not have enough reputation to comment on @blueberryfields ‘s answer)
@blueberryfields ‘s answer works well, but fails if there is no package to uninstall (which can be a problem if this “uninstall all” is part of a script or makefile). This can be solved with xargs -r when using GNU’s version of xargs:
If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there
is no input. This option is a GNU extension.
The case might be that one has to run this command several times to get an empty pip3 freeze --local.
回答 15
这是我卸载所有python软件包的最简单方法。
from pip import get_installed_distributions
from os import system
for i in get_installed_distributions():
system("pip3 uninstall {} -y -q".format(i.key))
This was the easiest way for me to uninstall all python packages.
from pip import get_installed_distributions
from os import system
for i in get_installed_distributions():
system("pip3 uninstall {} -y -q".format(i.key))
回答 16
仅使用即可提供跨平台支持pip:
#!/usr/bin/env pythonfrom sys import stderr
from pip.commands.uninstall importUninstallCommandfrom pip import get_installed_distributions
pip_uninstall =UninstallCommand()
options, args = pip_uninstall.parse_args([
package.project_name
for package in
get_installed_distributions()ifnot package.location.endswith('dist-packages')])
options.yes =True# Don't confirm before uninstall# set `options.require_venv` to True for virtualenv restrictiontry:print pip_uninstall.run(options, args)exceptOSErroras e:if e.errno !=13:raise e
print>> stderr,"You lack permissions to uninstall this package.
Perhaps run with sudo? Exiting."
exit(13)# Plenty of other exceptions can be thrown, e.g.: `InstallationError`# handle them if you want to.
#!/usr/bin/env python
from sys import stderr
from pip.commands.uninstall import UninstallCommand
from pip import get_installed_distributions
pip_uninstall = UninstallCommand()
options, args = pip_uninstall.parse_args([
package.project_name
for package in
get_installed_distributions()
if not package.location.endswith('dist-packages')
])
options.yes = True # Don't confirm before uninstall
# set `options.require_venv` to True for virtualenv restriction
try:
print pip_uninstall.run(options, args)
except OSError as e:
if e.errno != 13:
raise e
print >> stderr, "You lack permissions to uninstall this package.
Perhaps run with sudo? Exiting."
exit(13)
# Plenty of other exceptions can be thrown, e.g.: `InstallationError`
# handle them if you want to.
回答 17
这是对我有用的命令:
pip list | awk '{print $1}'| xargs pip uninstall -y
In my case, I had accidentally installed a number of packages globally using a Homebrew-installed pip on macOS. The easiest way to revert to the default packages was a simple:
In Command Shell of Windows, the command pip freeze | xargs pip uninstall -y won’t work. So for those of you using Windows, I’ve figured out an alternative way to do so.
Copy all the names of the installed packages of pip from the pip freeze command to a .txt file.
Then, go the location of your .txt file and run the command pip uninstall -r *textfile.txt*
Pip has no way of knowing what packages were installed by it and what packages were installed by your system’s package manager. For this you would need to do something like this
for rpm-based distros (replace python2.7 with your python version you installed pip with):
find /usr/lib/python2.7/ |while read f; do
if ! rpm -qf "$f" &> /dev/null; then
echo "$f"
fi
done |xargs rm -fr
for a deb-based distribution:
find /usr/lib/python2.7/ |while read f; do
if ! dpkg-query -S "$f" &> /dev/null; then
echo "$f"
fi
done |xargs rm -fr
then to clean up empty directories left over:
find /usr/lib/python2.7 -type d -empty |xargs rm -fr
I found the top answer very misleading since it will remove all (most?) python packages from your distribution and probably leave you with a broken system.
$ pip install tensorflow --user
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
$ pip install tensorflow --user
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
What am I doing wrong? So far I’ve used Python and pip with no issues.
Edit 1: This was tested on Windows (8, 8.1, 10), Mac and Linux. Change python3 to python according to your configuration. Change py3 to py2 in the url if you are using Python 2.x.
You need a 64-bit version of Python and in your case are using a 32-bit version. As of now Tensorflow only supports 64-bit versions of Python 3.5.x and 3.6.x on Windows. See the install docs to see what is currently supported
To check which version of Python you are running, type python or python3 to start the interpreter, and then type import struct;print(struct.calcsize("P") * 8) and that will print either 32 or 64 to tell you which bit version of Python you are running.
From comments:
To download a different version of Python for Windows, go to python.org/downloads/windows and scroll down until you see the version you want that ends in a “64”. That will be the 64 bit version that should work with tensorflow
C:\Users\YOURNAME>python
Python3.6.3(v3.6.3:2c5fed8,Oct32017,18:11:49)[MSC v.190064 bit (AMD64)] on win32
Type"help","copyright","credits"or"license"for more information.
On Windows 10, with Python 3.6.X version I was facing same then after checking deliberately , I noticed I had Python-32 bit installation on my 64 bit machine. Remember TensorFlow is only compatible with 64bit installation of python. Not 32 bit of Python
If we download Python from python.org , the default installation would be 32 bit. So we have to download 64 bit installer manually to install Python 64 bit. And then add below to PATH environment.
Then run gpupdate /Force on command prompt. If python command doesnt work for 64 bit restart your machine.
Then run python on command prompt. It should show 64 bit
C:\Users\YOURNAME>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Then run below command to install tensorflow CPU version(recommended)
pip3 install --upgrade tensorflow
Update – Python 3.7
Currently only Python 3.5 and Python 3.6 are supported officially. Tensorflow has not released binaries for Python 3.7 still officially, we might need to wait a little for it to be released. You can use Python 3.6.x alongside or Anaconda with Python<3.7 virtual environment for time being.
From tensorflow website: “You will need pip version 8.1 or later for the following commands to work”. Run this command to upgrade your pip, then try install tensorflow again:
If you are trying to install it on a windows machine you need to have a 64-bit version of python 3.5. This is the only way to actually install it. From the website:
TensorFlow supports only 64-bit Python 3.5 on Windows. We have tested the pip packages with the following distributions of Python:
Python 3.5 from Anaconda
Python 3.5 from python.org.
You can download the proper version of python from here (make sure you grab one of the ones that says “Windows x86-64”)
You should now be able to install with pip install tensorflow or python -m pip install tensorflow (make sure that you are using the right pip, from python3, if you have both python2 and python3 installed)
Remember to install Anaconda 3-5.2.0 as the latest version which is 3-5.3.0 have python version 3.7 which is not supported by Tensorflow.
I figured out that TensorFlow 1.12.0 only works with Python version 3.5.2. I had Python 3.7 but that didn’t work. So, I had to downgrade Python and then I could install TensorFlow to make it work.
Updated 11/28/2016: TensorFlow is now available in PyPI, starting with release 0.12. You can type
pip install tensorflow
…or…
pip install tensorflow-gpu
…to install the CPU-only or GPU-accelerated version of TensorFlow respectively.
Previous answer: TensorFlow is not yet in the PyPI repository, so you have to specify the URL to the appropriate “wheel file” for your operating system and Python version.
The full list of supported configurations is listed on the TensorFlow website, but for example, to install version 0.10 for Python 2.7 on Linux, using CPU only, you would type the following command:
# Ubuntu/Linux 64-bit, CPU only, Python 2.7(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.# Mac OS X, CPU only, Python 2.7:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl
# Mac OS X, GPU enabled, Python 2.7:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py2-none-any.whl
# Ubuntu/Linux 64-bit, CPU only, Python 3.4(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp34-cp34m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp34-cp34m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, CPU only, Python 3.5(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp35-cp35m-linux_x86_64.whl
# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp35-cp35m-linux_x86_64.whl
# Mac OS X, CPU only, Python 3.4 or 3.5:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py3-none-any.whl
# Mac OS X, GPU enabled, Python 3.4 or 3.5:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py3-none-any.whl
# Ubuntu/Linux 64-bit, CPU only, Python 2.7
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7
# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.
# Mac OS X, CPU only, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl
# Mac OS X, GPU enabled, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py2-none-any.whl
# Ubuntu/Linux 64-bit, CPU only, Python 3.4
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp34-cp34m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4
# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp34-cp34m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, CPU only, Python 3.5
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp35-cp35m-linux_x86_64.whl
# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp35-cp35m-linux_x86_64.whl
# Mac OS X, CPU only, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py3-none-any.whl
# Mac OS X, GPU enabled, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py3-none-any.whl
I had the same error when trying to install on my Mac (using Python 2.7). A similar solution to the one I’m giving here also seemed to work for Python 3 on Windows 8.1 according to a different answer on this page by Yash Kumar Verma
Solution
Step 1: go to The URL of the TensorFlow Python package section of the TensorFlow installation page and copy the URL of the relevant link for your Python installation.
Step 2: open a terminal/command prompt and run the following command: pip install --upgrade [paste copied url link here]
So for me it was the following: pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.0-py2-none-any.whl
Update (July 21 2017): I tried this with some others who were running on Windows machines with Python 3.6 and they had to change the line in Step 2 to:
python -m pip install [paste copied url link here]
Update (26 July 2018): For Python 3.6.2 (not 3.7 because it’s in 3.6.2 in TF Documentation), you can also use pip3 install --upgrade [paste copied URL here] in Step 2.
If you run into this issue recently (say, after Python 3.7 release in 2018), most likely this is caused by the lack of Python 3.7 support (yet) from the tensorflow side. Try using Python 3.6 instead if you don’t mind. There are some tricks you can find from https://github.com/tensorflow/tensorflow/issues/20444, but use them at your own risk. I used the one harpone suggested – first downloaded the tensorflow wheel for Python 3.6 and then renamed it manually…
I had the same problem. After uninstalling the 32-bit version of python and reinstalling the 64-bit version I tried reinstalling TensorFlow and it worked.
If you’re trying to install tensorflow in anaconda and it isn’t working, then you may need to downgrade python version because only 3.6.x is currently supported while anaconda has the latest version.
check python version: python --version
if version > 3.6.x then follow step 3, otherwise stop, the problem may be somewhere else
conda search python
conda install python=3.6.6
Check version again: python --version
If version is correct, install tensorflow (step 7)
If you are using the Anaconda Python installation, pip install tensorflow will give the error stated above, shown below:
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
According to the TensorFlow installation page, you will need to use the --ignore-installed flag when running pip install.
However, before this can be done see this link
to ensure the TF_BINARY_URL variable is set correctly in relation to the desired version of TensorFlow that you wish to install.
"TensorFlow supports Python 3.5.x and 3.6.x on Windows. Note that Python 3 comes with the pip3 package manager, which is the program you'll use to install TensorFlow."
Unfortunately my reputation is to low to command underneath @Sujoy answer.
In their docs they claim to support python 3.6.
The link provided by @mayur shows that their is indeed only a python3.5 wheel package. This is my try to install tensorflow:
Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\>python3 -m pip install --upgrade pip
Requirement already up-to-date: pip in d:\python\v3\lib\site-packages (10.0.0)
C:\>python3 -m pip -V
pip 10.0.0 from D:\Python\V3\lib\site-packages\pip (python 3.6)
C:\>python3 -m pip install --upgrade tensorflow
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
while python 3.5 seems to install successfully. I would love to see a python3.6 version since they claim it should also work on python3.6.
Quoted :
"TensorFlow supports Python 3.5.x and 3.6.x on Windows. Note that Python 3 comes with the pip3 package manager, which is the program you'll use to install TensorFlow."
There are multiple groups of answers to this question. This answer aims to generalize one group of answers:
There may not be a version of TensorFlow that is compatible with your version of Python. This is particularly true if you’re using a new release of Python. For example, there may be a delay between the release of a new version of Python and the release of TensorFlow for that version of Python.
In this case, I believe your options are to:
1) Downgrade to the previous version of Python.
2) Compile TensorFlow from the source code.
3) Wait for a matching version of TensorFlow.
Download the wheel from this link. Then from command line navigate to your download folder where the wheel is present and simply type in the following command –
brew uninstall python3
brew install python3
python3 --version # Verify that you see "Python 3.6.0"
pip install tensorflow # With python 3.6 the install succeeds
pip install jupyter # "ipython notebook" didn't work for me until I installed jupyter
ipython notebook # Finally works!
I had this problem on OSX Sierra 10.12.2. It turns out I had the wrong version of Python installed (I had Python 3.4 but tensorflow pypi packages for OSX are only for python 3.5 and up).
The solution was to install Python 3.6. Here’s what I did to get it working. Note: I used Homebrew to install Python 3.6, you could do the same by using the Python 3.6 installer on python.org
brew uninstall python3
brew install python3
python3 --version # Verify that you see "Python 3.6.0"
pip install tensorflow # With python 3.6 the install succeeds
pip install jupyter # "ipython notebook" didn't work for me until I installed jupyter
ipython notebook # Finally works!
C:\> pip3 install --upgrade tensorflow
To install the GPU version of TensorFlow, enter the following command:
C:\> pip3 install --upgrade tensorflow-gpu
If the following version of Python is not installed on your machine, install it now:
Python 3.5.x from python.org
TensorFlow only supports version 3.5.x of Python on Windows. Note that Python 3.5.x comes with the pip3 package manager, which is the program you’ll use to install TensorFlow.
To install TensorFlow, start a terminal. Then issue the appropriate pip3 install command in that terminal. To install the CPU-only version of TensorFlow, enter the following command:
C:\> pip3 install --upgrade tensorflow
To install the GPU version of TensorFlow, enter the following command:
C:\> pip3 install --upgrade tensorflow-gpu
edit: Manual installation and use of setuptools is not the standard process anymore.
If you’re running Python 2.7.9+ or Python 3.4+
Congrats, you should already have pip installed. If you do not, read onward.
If you’re running a Unix-like System
You can usually install the package for pip through your package manager if your version of Python is older than 2.7.9 or 3.4, or if your system did not include it for whatever reason.
Instructions for some of the more common distros follow.
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 2.x
Run the following command from a terminal:
sudo apt-get install python-pip
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 3.x
Run the following command from a terminal:
sudo apt-get install python3-pip
Note:
On a fresh Debian/Ubuntu install, the package may not be found until you do:
sudo apt-get update
Installing pip on CentOS 7 for Python 2.x
On CentOS 7, you have to install setup tools first, and then use that to install pip, as there is no direct package for it.
Good news! Python 3.4 (released March 2014) ships with Pip. This is the best feature of any Python release. It makes the community’s wealth of libraries accessible to everyone. Newbies are no longer excluded by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Nodejs, Haskell, Perl, Go–almost every other contemporary language with a majority open-source community. Thank you Python.
For me, this installed Pip at C:\Python27\Scripts\pip.exe. Find pip.exe on your computer, then add its folder (eg. C:\Python27\Scripts) to your path (Start / Edit environment variables). Now you should be able to run pip from the command line. Try installing a package:
ganesh@Ganesh:~$ python3 # Type in terminalPython3.6.6(default,Sep122018,18:26:19)# Your python3 version[GCC 8.0.120180414(experimental)[trunk revision 259383]] on linux
Type"help","copyright","credits"or"license"for more information.>>>
To install packages in Python always follow these steps:
If the package is for python 2.x: sudo python -m pip install [package]
If the package is for python 3.x: sudo python3 -m pip install [package]
Note: This is assuming no alias is set for python
Through this method, there will be no confusion regarding which python version is receiving the package.
Multiple Pythons
Say you have python3 ↔ python3.6 and python3.7 ↔ python3.7
To install for python3.6: sudo python3 -m pip install [package]
To instal for python3.7: sudo python3.7 -m pip install [package]
This is essentially the same method as shown previously.
Note 1
How to find which python, your python3 command spawns:
ganesh@Ganesh:~$ python3 # Type in terminal
Python 3.6.6 (default, Sep 12 2018, 18:26:19) # Your python3 version
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
brew install python3 # this installs python only
brew postinstall python3 # this command installs pip
Also note that you should check the console if the install finished successfully. Sometimes it doesn’t (e.g. an error due to ownership), but people simply overlook the log.
On 1st March 2018 the python formula will be upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link –force). We will maintain python2, python3 and python@3 aliases.
So to install Python 3, run the following command:
brew install python3
Then, the pip is installed automatically, and you can install any package by pip install <package>.
wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz
tar xvf Python-3.4.0.tar.xz
cd Python-3.4.0./configure
make
make test
sudo make install
wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz
tar xvf Python-3.4.0.tar.xz
cd Python-3.4.0
./configure
make
make test
sudo make install
When you finished installing all of them, pip3 will get installed automatically.
By default, the commands pipX and pipX.Y will be installed on all platforms (where X.Y stands for the version of the Python installation), along with the pip Python package and its dependencies.
The good thing is that It will also detect what version of python you have (even if it’s an environment of python in your custom location).
After this you can proceed normally with (for example)
Assuming you are in a highly restricted computer env (such as myself) without root access or ability to install packages…
I had never setup a fresh/standalone/raw/non-root instance of Python+virtualenv before this post. I had do quite a bit of Googling to make this work.
Decide if you are using python (python2) or python3 and set your PATH correctly. (I am strictly a python3 user.) All commands below can substitute python3 for python if you are python2 user.
Assumes you are using a Bourne-compatible shell, e.g., bash
Brilliantly, this virtualenv package includes a standalone version of pip and setuptools that are auto-magically installed into each new virtualenv. This solves the chicken and egg problem.
You may want to create an alias (or update your ~/.bashrc, etc.) for this final command to activate the python virtualenv during each login. It can be a pain to remember all these paths and commands.
Check your version of python now: which python3 should give: /path/to/new/virtualenv/bin/python3
Check pip is also available in the virtualenv via which pip… should give: /path/to/new/virtualenv/bin/pip
Then… pip, pip, pip!
Final tip to newbie Pythoneers: You don’t think you need virtualenv when you start, but you will be happy to have it later. Helps with “what if” installation / upgrade scenarios for open source / shared packages.
Be cautious if you’re using a Python install that’s managed by your
operating system or another package manager. get-pip.py does not
coordinate with those tools, and may leave your system in an
inconsistent state.
If your Linux distro came with Python already installed, you should be able to install PIP using your system’s package manager. This is preferable since system-installed versions of Python do not play nicely with the get-pip.py script used on Windows and Mac.
Then run the following command in the folder where you have downloaded
get-pip.py:
python get-pip.py
Warning: Be cautious if you are using a Python install that is managed
by your operating system or another package manager. get-pip.py does
not coordinate with those tools, and may leave your system in an
inconsistent state.
I’m able to update pip-managed packages, but how do I update pip itself? According to pip --version, I currently have pip 1.1 installed in my virtualenv and I want to update to the latest version.
What’s the command for that? Do I need to use distribute or is there a native pip or virtualenv command? I’ve already tried pip update and pip update pip with no success.
I tried all of these solutions mentioned above under Debian Jessie. They don’t work, because it just takes the latest version compile by the debian package manager which is 1.5.6 which equates to version 6.0.x. Some packages that use pip as prerequisites will not work as a results, such as spaCy (which needs the option –no-cache-dir to function correctly).
So the actual best way to solve these problems is to run get-pip.py downloaded using wget, from the website or using curl as follows:
To get this to work for me I had to drill down in the Python directory using the Python command prompt (on WIN10 from VS CODE). In my case it was in my “AppData\Local\Programs\Python\python35-32” directory. From there now I ran the command…
Open Command Prompt with Administrator Permissions, and repeat the command:
python -m pip install --upgrade pip
回答 8
pip版本10有问题。它将显示为错误:
ubuntu@mymachine-:~/mydir$ sudo pip install --upgrade pip
Traceback(most recent call last):File"/usr/bin/pip", line 9,in<module>from pip import main
ImportError: cannot import name main
pip version 10 has an issue. It will manifest as the error:
ubuntu@mymachine-:~/mydir$ sudo pip install --upgrade pip
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
The solution is to be in the venv you want to upgrade and then run:
In case you are using venv any update to pip install will result in upgrading the system pip instead of the venv pip. You need to upgrade the pip bootstrapping packages as well.
I had installed Python in C:\Python\Python36 so I went to the Windows command prompt and typed “cd C:\Python\Python36 to get to the right directory. Then entered the “python -m install –upgrade pip” all good!
Single Line Python Program
The best way I have found is to write a single line program that downloads and runs the official get-pip script. See below for the code.
The official docs recommend using curl to download the get-pip script, but since I work on windows and don’t have curl installed I prefer using python itself to download and run the script.
Here is the single line program that can be run via the command line using Python 3:
Precautions
It’s worth noting that running any python script blindly is inherently dangerous. For this reason, the official instructions recommend downloading the script and inspecting it before running.
That said, many people don’t actually inspect the code and just run it. This one-line program makes that easier.
Very Simple. Just download pip from https://bootstrap.pypa.io/get-pip.py . Save the file in some forlder or dekstop. I saved the file in my D drive.Then from your command prompt navigate to the folder where you have downloaded pip. Then type there
I’ve come across situations where a current version of a package seems not to be working and requires reinstallation. But pip install -U won’t touch a package that is already up-to-date. I see how to force a reinstallation by first uninstalling (with pip uninstall) and then installing, but is there a way to simply force an “update” to a nominally current version in a single step?
If you want to reinstall packages specified in a requirements.txt file, without upgrading, so just reinstall the specific versions specified in the requirements.txt file:
Downloading/unpacking http://pypi.python.org/packages/source/p/psycopg2/psycopg2
-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160Downloading psycopg2-2.4.tar.gz (607Kb):607Kb downloaded
Running setup.py egg_info for package from http://pypi.python.org/packages/sou
rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160Error: pg_config executable not found.Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...orwith the pg_config option in'setup.cfg'.Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info\psycopg2.egg-info
writing pip-egg-info\psycopg2.egg-info\PKG-INFO
writing top-level names to pip-egg-info\psycopg2.egg-info\top_level.txt
writing dependency_links to pip-egg-info\psycopg2.egg-info\dependency_links.txt
writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.txt'
warning: manifest_maker: standard file '-c'not found
Error: pg_config executable not found.Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...orwith the pg_config option in'setup.cfg'.----------------------------------------Command python setup.py egg_info failed with error code 1Storing complete log in C:\Documents andSettings\anlopes\Application Data\pip\p
ip.log
Downloading/unpacking http://pypi.python.org/packages/source/p/psycopg2/psycopg2
-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
Downloading psycopg2-2.4.tar.gz (607Kb): 607Kb downloaded
Running setup.py egg_info for package from http://pypi.python.org/packages/sou
rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info\psycopg2.egg-info
writing pip-egg-info\psycopg2.egg-info\PKG-INFO
writing top-level names to pip-egg-info\psycopg2.egg-info\top_level.txt
writing dependency_links to pip-egg-info\psycopg2.egg-info\dependency_links.txt
writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in C:\Documents and Settings\anlopes\Application Data\pip\p
ip.log
My question, I only need to do this to get the psycopg2 working?
Note: Since a while back, there are binary wheels for Windows in PyPI, so this should no longer be an issue for Windows users. Below are solutions for Linux, Mac users, since lots of them find this post through web searches.
Option 1
Install the psycopg2-binary PyPI package instead, it has Python wheels for Linux and Mac OS.
pip install psycopg2-binary
Option 2
Install the prerequsisites for building the psycopg2 package from source:
Debian/Ubuntu
Python 3
sudo apt install libpq-dev python3-dev
You might need to install python3.8-dev or similar for e.g. Python 3.8.
大多数答案还建议安装Python开发库。小心。如果仅使用发行版中安装的默认Python,则可以使用,但是如果您使用的是较新版本,则可能会引起问题。如果您在此计算机上构建了Python,那么您已经具有编译C / C ++库与Python交互所需的dev库。只要您使用的是正确的pip版本,即与python二进制文件安装在同一bin文件夹中的版本,您便都已准备就绪。无需安装旧版本。
The answers so far are too much like magic recipes. The error that you received tells you that pip cannot find a needed part of the PostgreSQL Query library. Possibly this is because you have it installed in a non-standard place for your OS which is why the message suggests using the –pg-config option.
But a more common reason is that you don’t have libpq installed at all. This commonly happens on machines where you do NOT have PostgreSQL server installed because you only want to run client apps, not the server itself. Each OS/distro is different, for instance on Debian/Ubuntu you need to install libpq-dev. This allows you to compile and link code against the PostgreSQL Query library.
Most of the answers also suggest installing a Python dev library. Be careful. If you are only using the default Python installed by your distro, that will work, but if you have a newer version, it could cause problems. If you have built Python on this machine then you already have the dev libraries needed for compiling C/C++ libraries to interface with Python. As long as you are using the correct pip version, the one installed in the same bin folder as the python binary, then you are all set. No need to install the old version.
Besides installing the required packages, I also needed to manually add PostgreSQL bin directory to PATH. $vi ~/.bash_profile
Add PATH=/usr/pgsql-9.2/bin:$PATH before export PATH. $source ~/.bash_profile $pip install psycopg2
Before you can install psycopg2 you will need to install the python-dev package.
If you’re working from Linux (and possibly other systems but i can’t speak from experience) you will need to make sure to be quite exact about what version of python your running when installing the dev package.
For example when I used the command:
sudo apt-get install python3-dev
I still ran into the same error when trying to
pip install psycopg2
As I am using python 3.7 I needed to use the command
sudo apt-get install python3.7-dev
Once I did this I ran into no more issues. Obviously if your on python version 3.5 you would change that 7 to a 5.
I’ve been battling with this for days, and have finally figured out how to get the “pip install psycopg2” command to run in a virtualenv in Windows (running Cygwin).
I was hitting the “pg_config executable not found.” error, but I had already downloaded and installed postgres in Windows. It installed in Cygwin as well; running “which pg_config” in Cygwin gave “/usr/bin/pg_config”, and running “pg_config” gave sane output — however the version installed with Cygwin is:
VERSION = PostgreSQL 8.2.11
This won’t work with the current version of psycopg2, which appears to require at least 9.1. When I added “c:\Program Files\PostgreSQL\9.2\bin” to my Windows path, the Cygwin pip installer was able to find the correct version of PostgreSQL, and I was able to successfully install the module using pip. (This is probably preferable to using the Cygwin version of PostgreSQL anyway, as the native version will run much quicker).
For lowly Windows users were stuck having to install psycopg2 from the link below, just install it to whatever Python installation you have setup. It will place the folder named “psycopg2” in the site-packages folder of your python installation.
After that, just copy that folder to the site-packages directory of your virtualenv and you will have no problems.
here is the link you can find the executable to install psycopg2
On macOS Mojave make sure you on newest update with Command Line Tools 10.3 – that worked for me – updated it with Software Update, previous version of Command Line Tools on Mojave did not work for me.
Is there any way to make pip play well with multiple versions of Python? For example, I want to use pip to explicitly install things to either my site 2.5 installation or my site 2.6 installation.
For example, with easy_install, I use easy_install-2.{5,6}.
And, yes — I know about virtualenv, and no — it’s not a solution to this particular problem.
# The system default python:
$ python -m pip install fish
# A virtualenv's python:
$ .env/bin/python -m pip install fish
# A specific version of python:
$ python-3.6-m pip install fish
The current recommendation is to use python -m pip, where python is the version of Python you would like to use. This is the recommendation because it works across all versions of Python, and in all forms of virtualenv. For example:
# The system default python:
$ python -m pip install fish
# A virtualenv's python:
$ .env/bin/python -m pip install fish
# A specific version of python:
$ python-3.6 -m pip install fish
Previous answer, left for posterity:
Since version 0.8, Pip supports pip-{version}. You can use it the same as easy_install-{version}:
On Windows, you can execute the pip module using a given Python version through the Python launcher, py.exe, if you chose to install it during Python 3 setup.
For this to work on any python version that doesn’t have pip already installed you need to download pip and do python*version* setup.py install. For example python3.3 setup.py install. This resolves the import error in the comments. (As suggested by @hbdgaf)
I had python 2.6 installed by default (Amazon EC2 AMI), but needed python2.7 plus some external packages for my application. Assuming you already installed python2.7 alongside with default python (2.6 in my case). Here is how to install pip and packages for non-default python2.7
Other answers show how to use pip with both 2.X and 3.X Python, but does not show how to handle the case of multiple Python distributions (eg. original Python and Anaconda Python).
I have a total of 3 Python versions: original Python 2.7 and Python 3.5 and Anaconda Python 3.5.
Here is how I install a package into:
Original Python 3.5:
/usr/bin/python3 -m pip install python-daemon
Original Python 2.7:
/usr/bin/python -m pip install python-daemon
Anaconda Python 3.5:
python3 -m pip install python-daemon
or
pip3 install python-daemon
Simpler, as Anaconda overrides original Python binaries in user environment.
Of course, installing in anaconda should be done with conda command, this is just an example.
Also, make sure that pip is installed for that specific python.You might need to manually install pip. This works in Ubuntu 16.04:
$ sudo easy_install-2.7 pip
Searchingfor pip
Best match: pip 1.1Adding pip 1.1 to easy-install.pth file
Installing pip-2.7 script to /usr/local/bin
Using/usr/lib/python2.7/dist-packages
Processing dependencies for pip
Finished processing dependencies for pip
$ sudo pip-2.7 install django
Downloading/unpacking django
DownloadingDjango-1.5.1.tar.gz (8.0Mb):8.0Mb downloaded
Running setup.py egg_info for package django
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from644 to 755
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
changing mode of /usr/local/bin/django-admin.py to 755Successfully installed django
Cleaning up...
$ python
Python2.7.3(default,Sep262012,21:51:14)[GCC 4.7.2] on linux2
Type"help","copyright","credits"or"license"for more information.>>>import django
>>>
So apparently there are multiple versions of easy_installandpip. It seems to be a big mess. Anyway, this is what I did to install Django for Python 2.7 on Ubuntu 12.10:
$ sudo easy_install-2.7 pip
Searching for pip
Best match: pip 1.1
Adding pip 1.1 to easy-install.pth file
Installing pip-2.7 script to /usr/local/bin
Using /usr/lib/python2.7/dist-packages
Processing dependencies for pip
Finished processing dependencies for pip
$ sudo pip-2.7 install django
Downloading/unpacking django
Downloading Django-1.5.1.tar.gz (8.0Mb): 8.0Mb downloaded
Running setup.py egg_info for package django
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from 644 to 755
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
changing mode of /usr/local/bin/django-admin.py to 755
Successfully installed django
Cleaning up...
$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>
Installation of multiple versions of Python and respective Packages.
Python version on the same windows machine : 2.7 , 3.4 and 3.6
Installation of all 3 versions of Python :
Installed the Python 2.7 , 3.4 and 3.6 with the below paths
PATH for all 3 versions of Python :
Made sure the PATH variable ( in System Variables ) has below paths included – C:\Python27\;C:\Python27\Scripts;C:\Python34\;C:\Python34\Scripts;C:\Python36\;C:\Python36\Scripts\;
Renaming the executables for versions :
Changed the python executable name in C:\Python36 and C:\Python34 to python36 and python34 respectively.
Checked for the command prompt with all versions :
Installing the packages separately for each version
回答 12
如果您有多个版本以及多个体系结构(32位,64位),则需要在版本末尾添加-32或-64。
对于Windows,请转到cmd并键入py –list,它将生成您已安装的版本。该列表将如下所示:
InstalledPythons found by py LauncherforWindows-3.7-64*-3.7-32-3.6-32
If you have multiple versions as well as multiple architectures (32 bit, 64 bit) you will need to add a -32 or -64 at the end of your version.
For windows, go to cmd and type py –list and it will produce the versions you have installed. The list will look like the following:
Installed Pythons found by py Launcher for Windows
-3.7-64 *
-3.7-32
-3.6-32
The full command as an example will be:
py -3.6-32 -m pip install (package)
If you want to get more indepth, to install a specific version of a package on a specific version of python, use ==(version) after the package. As an example,
Most of the answers here address the issue but I want to add something what was continually confusing me with regard to creating an alternate installation of python in the /usr/local on CentOS 7. When I installed there, it appeared like pip was working since I could use pip2.7 install and it would install modules. However, what I couldn’t figure out was why my newly installed version of python wasn’t seeing what I was installing.
It turns out in CentOS 7 that there is already a python2.7 and a pip2.7 in the /usr/bin folder. To install pip for your new python distribution, you need to specifically tell sudo to go to /usr/local/bin
sudo /usr/local/bin/python2.7 -m ensurepip
This should get pip2.7 installed in your /usr/local/bin folder along with your version of python. The trick is that when you want to install modules, you either need to modify the sudo $PATH variable to include /usr/local/bin or you need to execute
sudo /usr/local/bin/pip2.7 install <module>
if you want to install a new module. It took me forever to remember that sudo wasn’t immediately seeing /usr/local/bin.
回答 14
这是我对这个问题的看法。适用于Python3。主要特点是:
每个Python版本均从源代码编译
所有版本均在本地安装
不会以任何方式破坏系统的默认Python安装
每个Python版本都通过virtualenv隔离
步骤如下:
如果您以其他方式安装了多个额外的python版本,请摆脱它们,例如,删除$ HOME / .local / lib / python3.x等(以及全局安装的版本)。但是不要触摸系统的默认python3版本。
在以下目录结构下的不同python版本的下载源:
$HOME/
python_versions/: download Python-*.tgz packages here and"tar xvf" them.You'll get directories like this:
Python-3.4.8/
Python-3.6.5/
Python-3.x.y/
...
Here is my take on the problem. Works for Python3. The main features are:
Each Python version is compiled from source
All versions are installed locally
Does not mangle your system’s default Python installation in any way
Each Python version is isolated with virtualenv
The steps are as follows:
If you have several extra python versions installed in some other way, get rid of them, e.g., remove $HOME/.local/lib/python3.x, etc. (also the globally installed ones). Don’t touch your system’s default python3 version though.
Download source for different python versions under the following directory structure:
$HOME/
python_versions/ : download Python-*.tgz packages here and "tar xvf" them. You'll get directories like this:
Python-3.4.8/
Python-3.6.5/
Python-3.x.y/
...
At each “Python-3.x.y/” directory, do the following (do NOT use “sudo” in any of the steps!):
mkdir root
./configure --prefix=$PWD/root
make -j 2
make install
virtualenv --no-site-packages -p root/bin/python3.x env
At “python_versions/” create files like this:
env_python3x.bash:
#!/bin/bash
echo "type deactivate to exit"
source $HOME/python_versions/Python-3.x.y/env/bin/activate
Now, anytime you wish to opt for python3.x, do
source $HOME/python_versions/env_python3x.bash
to enter the virtualenv
While in the virtualenv, install your favorite python packages with
pip install --upgrade package_name
To exit the virtualenv and python version just type “deactivate”
UPDATE
It seems that --no-site-packages is deprecated. There’s an easy fix for this: Once you have activated the virtualenv, just point the HOME env variable to somewhere else than your actual home directory, i.e.:
export HOME=some/where/else
A nice way to do this in general is:
Create virtualenv
Activate virtualenv
If you want to “recycle” existing libraries to your virtualenv, softlink them from your existing install, i.e.
ln -s $HOME/.local/lib/python3.6/site-packages/numpy $PWD/venv/lib/python3.6/site-packages/
Do export PYTHONPATH=, export HOME=/some/other/dir
You can go to for example C:\Python2.7\Scripts and then run cmd from that path. After that you can run pip2.7 install yourpackage…
That will install package for that version of Python.
回答 18
这可能是完全错误的操作(我是python noob),但是我只是进去编辑了pip文件
#!/usr/bin/env python3 <-- I changed this line.# -*- coding: utf-8 -*-import re
import sys
from pip._internal import main
if __name__ =='__main__':
sys.argv[0]= re.sub(r'(-script\.pyw?|\.exe)?$','', sys.argv[0])
sys.exit(main())
This is probably the completely wrong thing to do (I’m a python noob), but I just went in and edited the pip file
#!/usr/bin/env python3 <-- I changed this line.
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())