Search code examples
pythonpycharminterpreter

PyCharm Virtual Environment Setup


I'm trying to get on with Python coding rather than fiddling about with settings getting in the way of development. Alas, it is not meant to be.

1 - I've installed Python 3.9 in Windows 10 from the Windows Store (running python in a powershell and instructions therein). 2 - I'm using PyCharm IDE.

I am very familiar with JetBrains products and building php projects. The transition to Python is not as straightforward. When I setup a new project and want to run code I need to set my configuration for the virtual environment.

I range from not being able to run any code through to perfect success with a lack of being able to import libraries in between.

In my toolkit is:

a) Edit Configuation - selecting a python interpreter. This never seems to make any difference no matter which one I choose. I only have options that are the right version but seemingly python.exe files in the project, in my Windows directory and all over the place.

b) Settings>PythonInterpreter>VirtualEnvironment>ExisitngLocation When I get it to work it's usually the python.exe in the Windows directory that pip installs everything in. Selecting that interpreter then locates all the packages I have installed and I can import all the libraries I want.

I would like to (i) understand why I have so many options (don't I just use python.exe because I've installed it somewhere) to pick a multitude of python.exe everytime I build a new project. I have missed this aspect of Python.

I would like to (ii) understand how to get a project to reference the libraries I have installed on my machine such that I can access them properly in my project and spend less time trying to wire everything up and more time actually building the project out.


Solution

  • I had a similar issue initially.

    My "solution" was to delete python from the Windows Store, install Anaconda and then follow these steps from a SO answer for enabling PowerShell to run python with conda

    Details in creating projects with PyCharm can be found here (a webpage on Anaconda).

    Then PyCharm just works... like a charm.