如何在 PyCharm 中使用已安装的软件包? [英] How do I use installed packages in PyCharm?

查看:84
本文介绍了如何在 PyCharm 中使用已安装的软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PyCharm 中,我添加了 Python 环境 /usr/bin/python.然而,

In PyCharm, I've added the Python environment /usr/bin/python. However,

from gnuradio import gr

作为一个未定义的引用而失败.但是,它在命令行的 Python 解释器中运行良好.

fails as an undefined reference. However, it works fine in the Python interpreter from the command line.

GNURadio 在 Pycharm 之外与 python 一起工作正常.一切都按照我想要的方式安装和配置.

GNURadio works fine with python outside of Pycharm. Everything is installed and configured how I want it.

Gnuradio 位于 /usr/local/lib/python2.7/site-packages/gnuradio

Gnuradio is located at /usr/local/lib/python2.7/site-packages/gnuradio

还有:

PYTHONPATH=/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/site-packages/gnuradio

PYTHONPATH=/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/site-packages/gnuradio

推荐答案

添加路径

进入文件→设置→项目设置→项目解释器.

Adding a Path

Go into File → Settings → Project Settings → Project Interpreter.

然后按配置解释器,并导航到路径"选项卡.

Then press configure interpreter, and navigate to the "Paths" tab.

按路径区域中的 + 按钮.您可以输入您希望它识别的模块的路径.

Press the + button in the Paths area. You can put the path to the module you'd like it to recognize.

打开 python 解释器,您可以在其中导入模块.

Open the python interpreter where you can import the module.

>> import gnuradio
>> gnuradio.__file__
"path/to/gnuradio"

最常见的文件夹结构如下:

Most commonly you'll have a folder structure like this:

foobarbaz/
  gnuradio/
    __init__.py
    other_file.py

您想将 foobarbaz 添加到此处的路径中.

You want to add foobarbaz to the path here.

这篇关于如何在 PyCharm 中使用已安装的软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆