简体   繁体   English

使用 Pip 在 Python 3.8 中成功安装模块但我无法导入它们?

[英]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:部分截图如下:

Project Layout项目布局图 1

Project Interpreter项目口译员图 2

Virtual Environment虚拟环境图 3

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 命令

  1. I was playing around PyCharm and found this option to "Activate Global Site Packages" --我在玩 PyCharm,发现这个选项可以“激活全球站点包”—— 在此处输入图片说明

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.

相关问题 使用 pip 安装后,无法在 python 中导入模块 - Can't import modules in python after installing them with pip 我已经在pip中上传了一个Python包,然后pip安装了这个包,但是我在Python Interpreter中无法导入这个包 - I have uploaded a Python package in pip, then pip installed this package, but I can't import this package in Python Interpreter 安装的Python模块 - Python无法找到它们 - Installed Python Modules - Python can't find them 无法导入使用 pip 安装的模块(anaconda python) - Can't import module installed with pip (anaconda python) 安装了 python package 与 pip 但不能导入说 ZEFE90A8E604A7C640E88D03A78D6 - Installed python package with pip but can't import said package 嗨,我刚刚用 pip 安装了请求,但我无法导入它 - Hi, I just installed requests with pip but I can't import it 我用 pip 安装了 OpenGL python 库,但是当我尝试使用 PyCharm 导入它时它不起作用 - I installed OpenGL python library with pip, but it doesn't work when I tried to import it using PyCharm import nltk Not working in Python (nltk and numpy successfully installed, pip working) - import nltk Not working in Python (nltk and numpy successfully installed, pip working) Flask看不到pip安装的模块 - Flask can't see modules installed by pip 无法在 jupyter notebook 中导入 pytagcloud 但我使用 pip 安装了该库 - Can't import pytagcloud in jupyter notebook but I installed the library using pip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM