[英]Installing lxml on Python 3 on a Mac
I have a new Mac and I installed python 3 using brew install python
.我有一台新 Mac,我使用brew install python
安装了 python 3。
[~]$ which python3 rbenv:system
/usr/local/bin/python3
[~]$ python3 --version rbenv:system
Python 3.8.6
I ran the following command: pip3 install -r requirements.txt which has lxml==4.5.2 in it.我运行了以下命令: pip3 install -r requirements.txt 其中包含 lxml==4.5.2 。
It installed fine with no errors.它安装得很好,没有错误。 If I run it again I get this:如果我再次运行它,我会得到这个:
Requirement already satisfied: lxml==4.5.2 in /usr/local/lib/python3.9/site-packages (from -r requirements.txt (line 1)) (4.5.2)
However whenever I try to import lxml, I get an error:但是,每当我尝试导入 lxml 时,都会出现错误:
[~]$ python3 rbenv:system
Python 3.8.6 (default, Oct 8 2020, 14:06:32)
[Clang 12.0.0 (clang-1200.0.32.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lxml'
>>>
Any ideas how to resolve this, I am using ohmyZSH so do I need to add anything to my .zshrc?任何想法如何解决这个问题,我正在使用 ohmyZSH,所以我需要在我的 .zshrc 中添加任何内容吗?
Some info on pip3:关于 pip3 的一些信息:
*[master][~/src/Arelle]$ which pip3 rbenv:system
/usr/local/bin/pip3
*[master][~/src/Arelle]$ pip3 --version rbenv:system
pip 20.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
The problem is that python3
and pip3
can be binaries that use different versions of Python.问题是python3
和pip3
可以是使用不同版本 Python 的二进制文件。 Furthermore, there are virtual environments, which give you a local site-packages
(folder for installed packages).此外,还有虚拟环境,可为您提供本地site-packages
(已安装包的文件夹)。
The best way to use pip COMMAND
is with python3 -m pip COMMAND
.使用pip COMMAND
的最佳方法是使用python3 -m pip COMMAND
。 That way you always know what Python installation your pip
is doing work for.这样你总是知道你的pip
正在为什么 Python 安装工作。
In your case, run在你的情况下,运行
python3 -m pip install lxml
in order to get lxml
where you want it.为了在你想要的地方获得lxml
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.