问题描述
我倾向于在Jupyter笔记本中运行我的代码,而这些笔记本则在python 3中运行.我的计算机上也有python 2.我安装了 pip3
,所以我能够安装专门针对python 3的软件包,但这似乎对我来说不起作用:
I tend to run my code in Jupyter notebooks, and these run in python 3. I also have python 2 on my computer. I installed pip3
so I'd be able to install packages specifically for python 3 but this doesn't seem to be working out for me:
mba$ pip3 install multidict
Collecting multidict
Using cached multidict-2.1.2.tar.gz
Building wheels for collected packages: multidict
Running setup.py bdist_wheel for multidict ... done
Stored in directory: /Users/mba/Library/Caches/pip/wheels/6e/f3/6a/c1ff64511c3dc2964ade4f9e59f4d7dfc050bd77e0fcc78ca5
Successfully built multidict
Installing collected packages: multidict
Successfully installed multidict-2.1.2
mba:~ $ python3
Python 3.5.2 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import multidict
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'multidict'
>>> import sys.
File "<stdin>", line 1
import sys.
^
SyntaxError: invalid syntax
>>> import sys
>>> sys.version
'3.5.2 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:52:12) \n[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)]'
>>>
请注意,使用 pip3
安装 multidict
成功,但是当我运行 python3
并尝试 import multidict
时,,这失败了.如何安装所需软件包的正确Python 3版本?
Notice that the multidict
install with pip3
succeeded, but when I ran python3
and tried to import multidict
, this failed. How can I install the proper Python 3 version of the package I want?
供参考,我使用的是Mac OS X El Capitan.我已经阅读了现有的SO帖子,并尝试遵循以下建议:
For reference, I'm on Mac OS X El Capitan. I've read the existing SO posts and tried following the advice in these:
这些还没有解决.感谢您的任何建议.
These have not done the trick. Thanks for any suggestions.
推荐答案
我把评论作为答案(4 年后)因为@user20272 建议它很有用.
I put comment as answer (after 4 years) because @user20272 suggested that it is useful.
也许您安装的 Python
很少,而 pip3
使用的版本与您期望的版本不同.
Maybe you have few Python
installed and pip3
uses different version than you expect.
首先,您可以检查版本( V
的上部)
First you can check versions (upper V
)
pip3 -V
python3 -V
您还可以检查您是否也没有类似的命令
You may also check if you don't have also similar commands
pip3.5 -V
pip3.6 -V
pip3.7 -V
python3.5 -V
python3.6 -V
python3.7 -V
有时候最简单的方法是使用 python
进行安装
Sometimes the simplest method is to use python
to install it
python3 -m pip install multidict
稍后,您可以尝试清理此混乱并将正确的 pip3.x
替换为 pip3
.
在Linux上(可能在MacOS上也可能),可以使用 pip3
和 pip3.x
转到文件夹,删除 pip3
并创建符号链接使用
On Linux (and probably on MacOS too) you can go to folder with pip3
and pip3.x
, remove pip3
and create symbolic link using
ln -s pip3.5 pip3
而不是复制文件.
在Linux上(可能在MacOS上也可以),您可以使用
pip 使用
On Linux (and probably on MacOS too) you can find folder with pip
using
which pip3
最终
whereis pip3
这篇关于为python 3安装软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!