如何在本地和安装的python包版本之间切换,包括IDE支持(PyCharm)?

fdbelqdn  于 8个月前  发布在  PyCharm
关注(0)|答案(1)|浏览(81)

我开发了一个软件包fhg_isi,目前已经安装了0.0.1版。
在本地版本0.0.2(正在开发中)和已安装版本之间切换的推荐方法是什么?
我已经能够通过修改系统路径来加载本地版本(如果我想使用安装的版本,我可以注解掉系统路径的修改)

import sys

# If you want to use the local version of fhg_isi package,
# insert its absolute path to the python system path, for example:
local_fhg_isi_path = 'C:/python_env/workspace/fhg_isi/src'
sys.path.insert(1, local_fhg_isi_path)  # out comment this line to use installed version

from fhg_isi.gis.geojson_factory import GeojsonFactory  # This import stays the same for both cases
...

参见:How can you import a local version of a python package?
PyCharm无法识别库的切换。如果按住Ctrl键并单击GeojsonFactory,我仍然会导航到已安装的版本,而不是本地版本。
=>有没有更方便的方法在包之间切换,包括IDE支持,而不修改所有的导入语句?

bsxbgnwa

bsxbgnwa1#

PyCharm的行为可能会受到Projekt Structure设置和运行配置选项Add source roots to PYTHONPATH的影响。
一旦我将“src”文件夹配置为Source文件夹(=>蓝色),导航就像预期的那样工作了。

另一种方法也可能是使用virtual environments并在它们之间切换,正如Giacomo在评论中建议的那样。

相关问题