In PyCharm, how do you add a directory from one project as a source to another project?(在 PyCharm 中,如何将一个项目中的目录作为源添加到另一个项目?)
问题描述
I have several python projects started from git repos, all related to each other, that are all open in one PyCharm window.
I have python code in one project, call it project B, that imports python packages from project A, but PyCharm can't find the source.
I've marked the directories with python packages in project A as source directories in PyCharm, and indeed other code in project A can lookup these python packages. But these source directories don't appear to be part of the lookup table for other projects in the same window.
Is there any way in PyCharm to make one project recognize directories from another project as a source directory?
You have to tell Pycharm to use Project A as another "Content Root" for Project B.
- From the upper bar, go to File -> Settings... -> Project: [yourprojectnamehere] -> Project Structure.
- Click on
+ Add Content Root
at the right panel - Select the Project A folder from the popup named
Select content root directory
- Click OK
Now, you'll see Project A is listed at the right panel.
- Click on Project A from the right panel
- Now, the content of project A is listed. Select the ones you want to be included as source. You can hold
Ctrl
and clickleft mouse button
to select multiple entities. - Click
Sources
from the upper bar to assign the selected entities as Source.
Now you should see Source Folders at the right panel.
UPDATE: As of at least Pycharm 2019.1.3, this seems to have changed, to be simpler thankfully.
- From the upper bar, go to File -> Settings... -> Project: [yourprojectnamehere] -> Project Dependencies.
- Select your project, and then click the checkboxes for each other project it's dependent on.
这篇关于在 PyCharm 中,如何将一个项目中的目录作为源添加到另一个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 PyCharm 中,如何将一个项目中的目录作为源添
基础教程推荐
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01