PyCharm: versioning .idea folder while keeping different interpreters across developers

不想你离开。 提交于 2019-12-21 20:22:53

问题


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:


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:

.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.



来源:https://stackoverflow.com/questions/20983545/pycharm-versioning-idea-folder-while-keeping-different-interpreters-across-dev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!