Dualphase
Dualphase

Reputation: 29

pycharm not using virtualenv python

The problem I am facing is similar to this: PyCharm not using my configured virtualenv interpreter

I am trying to run a python module in PyCharm in a virtual environment. I have set up the correct Project Interpreter and the Python interpreter to point to the VirtualEnv interpreter. Have I set it up incorrectly?

Python Interpreter:

enter image description here Project Interpreter:

enter image description here When I run I get this message:

/projects/DE/.env/bin/python -m training
Could not import runpy module
Traceback (most recent call last):
  File "/Users/deepak/anaconda/lib/python3.6/runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "/projects/DE/.env/lib/python3.6/importlib/__init__.py", line 57, in <module>
    import types
  File "/projects/DE/training/types.py", line 2, in <module>
import json
  File "/Users/deepak/anaconda/lib/python3.6/json/__init__.py", line 106, in <module>
from .decoder import JSONDecoder, JSONDecodeError
  File "/Users/deepak/anaconda/lib/python3.6/json/decoder.py", line 3, in <module>
import re
  File "/projects/DE/.env/lib/python3.6/re.py", line 122, in <module>
import enum
  File "/projects/DE/.env/lib/python3.6/enum.py", line 2, in <module>
from types import MappingProxyType, DynamicClassAttribute
ImportError: cannot import name 'MappingProxyType'```

I am not sure why PyCharm is using the Anaconda python. I am not sure if there are any other places where the interpreter needs to be changed to point to the virtualenv.

The same command (/projects/DE/.env/bin/python -m training) seems to work when I run from the terminal.

What change can I make so that I can run the module from PyCharm?

Upvotes: 2

Views: 5018

Answers (1)

Viral Modi
Viral Modi

Reputation: 2135

In Pycharm version 2017.3, you can go to Pycharm -> Preferences -> Project -> Project Interpreter -> -> settings button on the right of the python interpreter text box -> Add local

This will open a new window with virtualenv Environment as one of the options on the left. On Selecting it, you will get an option to make a new virtualenv environment or use an existing virtual environment. Here next to the dropdown text box, you can click "..." and browse to your existing virtualenv created using pyenv and select it. It will select this virtualenv when you start terminal from Pycharm and also use the corresponding python interpreter as set while creating that virtualenv.

enter image description here

Upvotes: 1

Related Questions