如何将 pip3 用于 python 3.6 而不是 python 3.5?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46820625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use pip3 for python 3.6 instead of python 3.5?
提问by charlesreid1
I'm using Kali dist so I have already installed Python 2.7, 3.5 and 3.6. Commands 'python' and 'pip' are associated with Python 2.7. But the 'python3' uses Python 3.6 while pip3 is installing packages for Python 3.5.
When I tried to create an venv:
我正在使用 Kali dist,所以我已经安装了 Python 2.7、3.5 和 3.6。命令“python”和“pip”与 Python 2.7 相关联。但是 'python3' 使用 Python 3.6,而 pip3 正在为 Python 3.5 安装软件包。
当我尝试创建一个 venv 时:
pip3 -p python3.6 virtualenv myenv
I've got an error:
我有一个错误:
no such option: -p
How can I associate pip3 with Python 3.6 instead of Python 3.5?
如何将 pip3 与 Python 3.6 而不是 Python 3.5 相关联?
回答by charlesreid1
Your version of pip is inextricably linked to your version of Python, you cannot tell pip "use this Python" or "use that Python." If you have a version mismatch between pip3 (using Python 3.X) and python3 (being Python 3.Y), it means your problem is with multiple overlapping distributions of Python and a weirdly configured $PATH
.
您的 pip 版本与您的 Python 版本密不可分,您不能告诉 pip “使用这个 Python”或“使用那个 Python”。如果 pip3(使用 Python 3.X)和 python3(即 Python 3.Y)之间的版本不匹配,则意味着您的问题在于 Python 的多个重叠分布和奇怪配置的$PATH
.
If you run pip3 --version
it will tell you the site-packages directory and Python version number that pip3 is associated with.
如果您运行pip3 --version
它,它会告诉您 pip3 关联的站点包目录和 Python 版本号。
If you run python3
and then execute >>> import site; site.getsitepackages()
, it should print the site-packages directory your python3
is using.
如果您运行python3
然后执行>>> import site; site.getsitepackages()
,它应该打印您python3
正在使用的 site-packages 目录。
If these do not match, you've got path problems and you'll need to post more information about what operating system you're on, what Python distributions you're using, and how you installed them.
如果这些不匹配,则您遇到了路径问题,您需要发布有关您使用的操作系统、使用的 Python 发行版以及安装方式的更多信息。
Update/Summary of Comment Thread:Original poster had a distribution-bundled Python 3.6 installed alongside a self-installed Python 3.5. The pip3 on their path was associated with Python 3.6 (system Python), while the command python3 was associated with Python 3.5 (their self-installed Python). Resolution:
评论主题的更新/摘要:原始海报安装了分发捆绑的 Python 3.6 和自行安装的 Python 3.5。他们路径上的 pip3 与 Python 3.6(系统 Python)相关联,而命令 python3 与 Python 3.5(他们自行安装的 Python)相关联。解析度:
Run which -a python3
to find Python 3.5. Add the location of Python 3.5 to your $PATH
. (Do it in .profile
or .bash_profile
to make it permanent.)
运行which -a python3
以找到 Python 3.5。将 Python 3.5 的位置添加到您的$PATH
. (这样做.profile
或.bash_profile
使其永久化。)
回答by Lawrence D'Oliveiro
You can explicitly run the pip3
script with a particular Python version, by prefixing it with the appropriate python3.
xcommand:
您可以pip3
使用特定的 Python 版本显式运行脚本,方法是在它前面加上适当的python3.
x命令:
ldo@theon:~> pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
ldo@theon:~> python3.5 $(which pip3) --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
回答by Den-Jason
When you install Python3, see if there's a comment such as this:
Ignoring ensurepip failure: pip 9.0.1 requires SSL/TLS
安装Python3的时候看看有没有这样的注释:
Ignoring ensurepip failure: pip 9.0.1 requires SSL/TLS
You might see entries like this in the log:
您可能会在日志中看到这样的条目:
INFO: Can't locate Tcl/Tk libs and/or headers
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _dbm _gdbm
_lzma _sqlite3 _ssl
_tkinter readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
atexit pwd time
This answer describes using ensurepip https://stackoverflow.com/a/38250442/1607937
这个答案描述了使用 ensurepip https://stackoverflow.com/a/38250442/1607937
Also see this regarding openssl "SSL module in Python is not available" when installing package with pip3
另请参阅有关使用 pip3 安装软件包时openssl “Python 中的 SSL 模块不可用”的相关信息
回答by John Schmitt
First find the right version of python you want to use:
首先找到您要使用的正确版本的python:
$ which -a python3.6
/usr/bin/python3.6
then invoke that instance of python directly, e.g.
然后直接调用python的那个实例,例如
$ /usr/bin/python3.6 -m venv
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] ENV_DIR [ENV_DIR ...]
venv: error: the following arguments are required: ENV_DIR
Next, pip
does not create virtual environments. The module venv
does. Read the venv
documentationfor recommended usage. In your case, you might want:
接下来,pip
不创建虚拟环境。该模块venv
可以。阅读该venv
文档的推荐用法。在您的情况下,您可能需要:
$ /usr/bin/python3.6 -m venv myenv