简体   繁体   English

使用PyCharm导入python包时遇到问题

[英]Trouble importing python packages using PyCharm

I've been trying to install simple packages for python such as numpy and pandas, and while I am able to install the package manually from the command line using pip as soon as I try to import it PyCharm can't find it. 我一直在尝试为python安装诸如numpy和pandas之类的简单软件包,尽管我能够在导入后尽快使用pip从命令行手动安装该软件包,但PyCharm找不到它。 I have manually configured the path, with no luck. 我已经手动配置了路径,没有运气。

PyCharm can also not find the packages I want to install itself and produces a connection timeout, this could be because I am working from a secure network. PyCharm也找不到我要自行安装的软件包并产生连接超时,这可能是因为我正在安全的网络上工作。

Still pretty new to python and software dev in general, I apologise in advance if I'm being stupid, but no other similar threads are solving the issue. 总体来说,对于python和软件开发人员来说还是很新的,如果我很愚蠢,我会提前道歉,但是没有其他类似的线程可以解决这个问题。

I am operating on windows 7. The error I get is: 我在Windows 7上进行操作。出现的错误是:

C:\Users\james.alexander\PycharmProjects\Test.py\venv1\Scripts\python.exe C:/Users/james.alexander/PycharmProjects/Test.py/testfile.py
Traceback (most recent call last):
  File "C:/Users/james.alexander/PycharmProjects/Test.py/testfile.py", line 1, in <module>
    import numpy
ModuleNotFoundError: No module named 'numpy'

I think PyCharm use a virtualenv, installing via pip won't work since it will install the package in your local env. 我认为PyCharm使用virtualenv,通过pip安装将无法工作,因为它将在您的本地环境中安装该软件包。

Check https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html 检查https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html

Try This: 尝试这个:

Step 1: Ctrl+Alt+s 步骤1: Ctrl+Alt+s

Step 2: Look for Project Interpreter Under Project 第2步:寻找Project InterpreterProject

Step 3: Look for + In the right corner of prompt box. 步骤3:在提示框的右上角查找+

Step 4: Search and select your required package. 步骤4:搜索并选择所需的软件包。 And Install button is just below. Install按钮就在下面。

First check the Project Interpreter in your pycharm. 首先检查pycharm中的Project Interpreter。 File > Settings >Project >Project Interpreter Check the version of python there (python2 or python3) And check if you are using any virtual environment 文件>设置>项目>项目解释器检查那里的python版本(python2或python3),并检查您是否在使用任何虚拟环境

And see what version python you have installed For python3 you may have to use "pip3 install pkgname" For python2 use "pip install pkgname" 并查看已安装的python版本。对于python3,您可能必须使用“ pip3 install pkgname”。对于python2,请使用“ pip install pkgname”

In PyCharm, you can install modules from within the app. 在PyCharm中,您可以从应用程序内安装模块。 Simply access your preferences, then under 'Project Interpreter', you will find a table containing your installed modules. 只需访问您的首选项,然后在“项目解释器”下,您将找到一个包含已安装模块的表。 To install a new one, click the + symbol on the bottom - left, then search for the appropriate package, eg numpy. 要安装新软件包,请单击左下方的+符号,然后搜索适当的软件包,例如numpy。 Once you've found it, simply click 'Install Package'. 找到它后,只需单击“安装软件包”。 The module is now installed and ready to use! 现在,该模块已安装并可以使用!

EDIT: I've just seen that someone else has already posted this answer, sorry about that :) 编辑:我刚刚看到其他人已经发布了此答案,对此表示抱歉:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM