[英]Successfully installed modules in Python 3.8 using Pip but I can't import them?
I'm a Python newbie.我是 Python 新手。 I have Python 3.8 installed, but my Macbook is running Python 2.7.
我安装了 Python 3.8,但我的 Macbook 运行的是 Python 2.7。 I wasn't able to install Pip initially, but after looking up some Q&As, I installed Pip using this command:
我最初无法安装 Pip,但在查找了一些问答后,我使用以下命令安装了 Pip:
pip3 install --upgrade --force pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
Successfully installed pip-20.0.2
pip --version
pip 20.0.2 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
Following that, I installed some modules successfully:之后,我成功安装了一些模块:
pip install python-docx
Collecting python-docx
Downloading python-docx-0.8.10.tar.gz (5.5 MB)
|████████████████████████████████| 5.5 MB 2.4 MB/s
Collecting lxml>=2.3.2
Downloading lxml-4.5.0-cp38-cp38-macosx_10_9_x86_64.whl (4.6 MB)
|████████████████████████████████| 4.6 MB 11.3 MB/s
Installing collected packages: lxml, python-docx
Running setup.py install for python-docx ... done
Successfully installed lxml-4.5.0 python-docx-0.8.10
I can't seem to import them into Python.我似乎无法将它们导入 Python。 The "Site Packages" folders are orange, compared to the rest which are grey.
“站点包”文件夹是橙色的,而其余文件夹是灰色的。 I have uploaded a picture below, you can take a look:
我在下面上传了一张图片,你可以看看:
Here's the output for pip versions:这是 pip 版本的输出:
which -a pip
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip
which -a pip3
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip3
/usr/local/bin/pip3
Could it be a project interpreter issue?这可能是项目解释器的问题吗? Some screenshots below:
部分截图如下:
It's not just this module, I can't import all the modules that I have installed using Pip.不光是这个模块,我用pip安装的所有模块都不能导入。 Please help me!
请帮我! Thanks!!
谢谢!! :)
:)
Solved this issue with the help of @DavidCullen and @a_guest在@DavidCullen 和@a_guest 的帮助下解决了这个问题
So previously I have installed the modules on the system of my MacBook, but in PyCharm, I was actually in the Virtual Environment.所以之前我已经在我的 MacBook 的系统上安装了这些模块,但是在 PyCharm 中,我实际上是在虚拟环境中。 These two didn't link.
这两个没有联系。
After I understood the concept, there are two ways to sort the issue - 1. suggested by @DavidCullen -- run source venv/bin/activate
in the Terminal in PyCharm, and then use the Pip commands在我理解了这个概念之后,有两种方法可以对问题进行排序 - 1.@DavidCullen 建议 - 在 PyCharm 的终端中运行
source venv/bin/activate
,然后使用 Pip 命令
I was able to import my installed modules after these.在这些之后,我能够导入我安装的模块。
Hi i also faced the same problem previously to get out of the problem install it in the powershell or cmd or the place where you are executing the code.嗨,我以前也遇到过同样的问题,以解决问题,将它安装在 powershell 或 cmd 或执行代码的地方。 this has worked for me.
这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.