I'm working on a Django project that is using Python 3 in a virtualenv. I just came across fabric, which only works under Python 2, so I installed it system wide instead of in my virtualenv (is it even possible to put this in my Python 3 virtualenv, btw?).
The problem here is that I've set PyCharm to use Python 3 as interpreter and having fabric installed for Python 2. When I edit my fabric file it says that all imports from fabric are unknown.
Is there any way I can solve this? Any way to assign my fabric file to use the Python 2 interpreter instead of Python 3, or some other solution?
This is possible to do (at least with the current PyCharm 2018.2.4), but it takes some manual effort and cannot be done through the GUI.
.idea
folder of your projectmodules.xml
<module>
line and change the fileurl
and filepath
attributes. Mine looked like this when I was done:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/dataops.iml" filepath="$PROJECT_DIR$/.idea/dataops.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/dataops_py27.iml" filepath="$PROJECT_DIR$/.idea/dataops_py27.iml" />
</modules>
</component>
</project>
Copy $PROJECT_NAME.iml
to the name you gave your new module. In my case I did:
cp dataops.iml dataops_py27.iml
Open your project back up in PyCharm and go to Preferences > Project > Project Interpreter.
You will see the two modules (the initial module and the new one you just created). Select the new one and configure the interpreter by clicking the gear icon in the upper right corner of the window and selecting Add...
Go to Preferences > Project > Project Structure.
Make sure your new module is selected, remove the old content root and add a new one.
Note: If you have many files in the folder and do not want the newly added interpreter to apply to all of them you can exclude them in the Exclude files:
text box located at the bottom of the Preferences > Project > Project Structure
setting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With