PyCharm 无法识别在开发模式下安装的模块 [英] PyCharm does not recognize modules installed in development mode

查看:51
本文介绍了PyCharm 无法识别在开发模式下安装的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PyCharm 3.4.1 专业版中有两个纯 python 项目.第一个,我们称之为 p(类似于包),被构造为一个 setuptools 包(即带有 setup.py、所有要求等,但它不会上传到 pypi 或任何其他在线存储库).第二个,我们称之为 s(类似于脚本),只是一个带有两个模块的 python 脚本.

I have two pure python projects in PyCharm 3.4.1 Professional Edition. The first one, let's call it p (like package), is structured as a setuptools package (i.e. with setup.py, all requirements etc., however it is not uploaded to pypi or any other online repository). The second one, let's call it s (like script), is just a python script along with two modules.

项目 s 被(在 PyCharm 中)配置为使用专用的 virtualenv,我们称之为 venv.

Project s is (in PyCharm) configured to use a dedicated virtualenv, let's call it venv.

我遇到的问题如下:当我像这样在 venv 中安装项目(包)p 时:

The problem I have is the following: when I install the project (package) p in venv like this:

$ source /path/to/venv/bin/activate
(venv)$ cd /path/to/p
(venv)$ python3 setup.py develop

在项目s 的PyCharm 中,import p 语句错误并显示消息No module named p.但是,当我在 s 中运行脚本时,一切都很好,唯一的问题是 PyCharm IDE 抱怨找不到模块.我可以忍受这个,但它很烦人...

in PyCharm in project s, import p statements are errorneous with message No module named p. However, when I run the script in s, everything is fine, the only problem is the PyCharm IDE complaining about not being able to find the module. I can live with this but it is very annoying...

为什么会这样?它是 PyCharm 的东西还是与包装相关的东西?请参阅下面的新闻.

项目/包p的结构如下:

p/
|
+- p/
|  |
|  +- __init__.py
|  +- other subpackages, modules, etc.
+- setup.py
+- README, DESCRIPTION, setup.cfg, etc.

当我将 PyCharm 项目 p 配置为存在于它自己的 virtualenv 中并在开发模式下将其安装在那里时,一切正常.

When I configure the PyCharm project p to live in its own virtualenv and install it there in development mode, everything works fine.

新闻

这个问题在 PyCharm 5.0.4 中仍然存在.但是,我设法解决了它,有点.

This problem is still present in PyCharm 5.0.4. However, I managed to solve it, kind-of.

由于某些原因,我不得不从 pypi 安装另一个包.我是通过 PyCharm 完成的,方法是转到 File -> Settings -> Project: -> Project Interpreter,然后点击绿色的 +,找到包并按下 Install Package 按钮.安装后,python3 setup.py develop安装的包被PyCharm很好的识别了.显然问题在于 PyCharm 没有一些与现实同步的缓存.

For some reasons I had to install another package from pypi. I did it through PyCharm by going to File -> Settings -> Project: -> Project Interpreter, there clicking on the green +, finding the package and pressing the Install Package button. After the installation, the package installed by python3 setup.py develop is well recognized by PyCharm. Obviously the problem was that PyCharm didn't have some cache in sync with reality.

那么新的问题是,是否可以告诉 PyCharm 更新其关于使用的 Python 环境的缓存?

So the new question is, can PyCharm be told to update its caches regarding the used python environment?

推荐答案

从 Pycharm 2016.1.4(专业版)开始,似乎打开一个不同的项目(例如通过打开最近的)然后打开原来的项目会使 Pycharm 重新索引已安装的包,从而识别开发安装的包.

As of Pycharm 2016.1.4 (professional edition), it seems that opening a different project (e.g. through Open Recent) and then opening the original one makes Pycharm reindex the installed packages and hence recognize the develop-installed packages.

这对我来说已经足够了.

This is enough for me.

这篇关于PyCharm 无法识别在开发模式下安装的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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