1

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.

nickL
  • 1,536
  • 2
  • 10
  • 15
  • 3
    Have you read the [documentation](https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html)? – It_is_Chris Jan 19 '22 at 20:58
  • 1
    for option (ii) check out using a requierments.txt file for all you library dependencies: https://www.jetbrains.com/help/pycharm/managing-dependencies.html – pugi Jan 19 '22 at 21:01
  • @pugi That's not that relevant for a NewProject with Hello World. That doesn't even run despite the intepreter pointing to the installed python. I fail to create a virtual environment when creating a new project with nothing in it. – nickL Jan 19 '22 at 21:24
  • @It_is_Chris you bet. "Setup a simple Project" https://www.jetbrains.com/help/pycharm/creating-and-running-your-first-python-project.html#creating-simple-project Step 1. Can't get beyond that if I go back to basics... – nickL Jan 19 '22 at 21:25
  • @nickL did you look at the documentation I linked about configuring virtual environments? Also, how are you creating your virtual environments: Virtualenv, conda, etc? Are you activating the env before installing packages? Do you know the path to the python interpreter for your virtual env? – It_is_Chris Jan 19 '22 at 21:35
  • @It_is_Chris Yes - but I don't get anwhere. Fresh project, no main.py and then try to setup the interpreter by pointing at the system python interpreter. If I navigate to the exe through the file dialogue PyCharm gives me the error it can't find it when I try and run a print('hello') project in a newly created main.py. – nickL Jan 19 '22 at 21:54
  • I had a similar issue initially. My "solution" was to delete python from the Windows Store, install conda and follow the steps for allowing PowerShell to run python with conda. Then PyCharm just works... like a charm. – Breno Jan 19 '22 at 21:54
  • 1
    @Breno It is magic! It solved the problem and it's much clearer. Do you want to put it as the answer and I'll say you answered it... – nickL Jan 19 '22 at 23:57

1 Answers1

1

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.

Breno
  • 748
  • 8
  • 18