[英]How do I set Pycharm to start my project from a specific folder deep within my Git repository
I am working on a Python project which is contained a few folders deep in my Git repo. 我正在研究一个Python项目,该项目在我的Git存储库中包含一些文件夹。 eg
例如
/home/userA/git_repo/product/utils/python_fwk/backend/my_project
Under this Git repo there are additional Python projects, belonging to other users. 在此Git存储库下,还有其他Python项目,这些项目属于其他用户。
When I start a new project and clone the Git repo, my project is set to start at /home/userA/git_repo/...
, so now, when I import my packages into my code I need to: 当我开始一个新项目并克隆Git存储库时,我的项目设置为
/home/userA/git_repo/...
,因此现在,当我将包导入到我的代码中时,我需要:
from product.utils.python_fwk_backend.my_project.some_package.2nd_package import MyPackage
Since the python project is located under .../my_project
I would like my imports to be as follows 由于python项目位于
.../my_project
我希望导入如下
from some_package.2nd_package import MyPackage
One way I found is to add additional content paths to the project. 我发现的一种方法是向项目添加其他内容路径。
Pycharm -> File -> Settings -> Project: YOUR_PROJECT_NAME -> Project Structure -> Add Content Root
Now add the path that matches the project path 现在添加与项目路径匹配的路径
/home/userA/git_repo/product/utils/python_fwk/backend/my_project
This requires to remove the initial Content Root Path 这需要删除初始内容根路径
/home/userA/git_repo/product/utils/python_fwk/backend/my_project
because there can't be overlapping of paths. 因为路径不能重叠。
Now I can import using the shorter path 现在我可以使用较短的路径导入
from some_package.2nd_package import MyPackage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.