PyCharm: versioning .idea folder while keeping dif

2019-04-11 20:39发布

We are using PyCharm as the Python IDE for a project. Developers use different kind of OS setup, e.g., python path is not the same for some of us (some have local interpreter stored at different location or remote interpreters).

Unfortunately, python interpreter path is stored in the .idea PyCharm project folder (.iml file). It then leads to conflicts or python path overriding when merging branches with Mercurial.

We would like to keep tracking under version control the .idea folder and the .iml file since they do hold meaningful settings that should be shared across developers (but the python path).

Is there a way to setup the python interpreter path outside the PyCharm project?

Note: There's an interesting SO question (Share a PyCharm project across multiple operating systems (different interpreter paths)) but it force developers to rename their interpreter entry (and have a single interpeter) for all their other projects.

1条回答
迷人小祖宗
2楼-- · 2019-04-11 20:56

You can somewhat abstract explicit Python interpreter location from your project by using virtualenv and agreeing on the common name between developers. This solution is is an extension of the mentioned SO question.

Set-up workstation:

# .bash_profile 
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh  

Create virtual environment:

$ mkvirtualenv marketplace-tests
New python executable in marketplace-tests/bin/python

Set up the interpreter in PyCharm:

enter image description here

.idea contains only the interpreter name, not the location:

./stackoverflow-test.iml:    <orderEntry type="jdk" jdkName="we-all-agreed-on-that-name-interpreter" jdkType="Python SDK" />
./misc.xml:  <component name="ProjectRootManager" version="2" project-jdk-name="we-all-agreed-on-that-name-interpreter" project-jdk-type="Python SDK" />

Now, when the the project is opened a workstation first time, it will error out and complain that "Invalid Python interpreter selected for the project". Developer will have to point "we-all-agreed-on-that-name-interpreter" to local virtual environment and make sure that "Associate this virtual environment with the current project" checkbox is on.

查看更多
登录 后发表回答