在 PyCharm 中,如何将一个项目中的目录作为源添加到另一个项目中? [英] In PyCharm, how do you add a directory from one project as a source to another project?

查看:124
本文介绍了在 PyCharm 中,如何将一个项目中的目录作为源添加到另一个项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个从 git repos 开始的 python 项目,它们都相互关联,都在一个 PyCharm 窗口中打开.

I have several python projects started from git repos, all related to each other, that are all open in one PyCharm window.

我在一个项目中有 python 代码,称为项目 B,它从项目 A 导入 python 包,但 PyCharm 找不到源代码.

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.

我已经将项目A中的python包目录标记为PyCharm中的源目录,项目A中的其他代码确实可以查找这些python包.但是这些源目录似乎不是同一窗口中其他项目的查找表的一部分.

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.

PyCharm 有没有办法让一个项目将另一个项目的目录识别为源目录?

Is there any way in PyCharm to make one project recognize directories from another project as a source directory?

推荐答案

你必须告诉 Pycharm 使用项目 A 作为项目 B 的另一个内容根".

You have to tell Pycharm to use Project A as another "Content Root" for Project B.

  1. 从上方的栏中,转到文件 -> 设置... -> 项目:[yourprojectnamehere] -> 项目结构.
  2. 点击右侧面板中的+ Add Content Root
  3. 从名为 Select content root directory
  4. 的弹出窗口中选择 Project A 文件夹
  5. 点击确定

现在,您会看到右侧面板中列出了项目 A.

Now, you'll see Project A is listed at the right panel.

  1. 点击右侧面板中的项目 A
  2. 现在,列出了项目 A 的内容.选择要作为源包含的那些.您可以按住Ctrl并单击鼠标左键来选择多个实体.
  3. 点击上方栏中的Sources,将所选实体指定为Source.
  1. Click on Project A from the right panel
  2. Now, the content of project A is listed. Select the ones you want to be included as source. You can hold Ctrl and click left mouse button to select multiple entities.
  3. Click Sources from the upper bar to assign the selected entities as Source.

现在您应该在右侧面板中看到源文件夹.

Now you should see Source Folders at the right panel.

更新:至少从 Pycharm 2019.1.3 开始,这似乎发生了变化,谢天谢地变得更简单了.

UPDATE: As of at least Pycharm 2019.1.3, this seems to have changed, to be simpler thankfully.

  1. 从上方的栏中,转到文件 -> 设置... -> 项目:[yourprojectnamehere] -> 项目依赖项.
  2. 选择您的项目,然后单击它所依赖的每个其他项目的复选框.

这篇关于在 PyCharm 中,如何将一个项目中的目录作为源添加到另一个项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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