r/learnpython 2d ago

Brand new to all of this

Hi there!
College student here and completely brand new to using Python. I am in a level 1 Python class and I don't think I have it installed correctly on my PC. We have to use Visual Studia with it and when I did a test page, and test page 2, I go to search it in Command Prompt and it says it doesn't exist. Could the path be wrong or is it something else? TIA and if you need any screen shots let me know.

0 Upvotes

15 comments sorted by

1

u/Gtdef 2d ago

It's hard to say exactly what went wrong.

If you install it with winget, it will handle the path itself for sure. You just reload the terminal, type py --version and it should work.

If you install it from the python site, you will have to follow the instructions of the installation wizard. It may handle the path itself, or it may fail (has happened to me before). Try typing "env" on windows search (the windows button on your keyboard), and click on "Environment Variables". You will see 2 tables there, with Path/Variable columns. You have to doubleclick on the "Path" line in each table and check if the Python isntallation directory exists somewhere there. If not you will have to add it manually in the user path.

This is also a good chance to sharpen the most important developer skill, googling. Try googling for "how to add python in path", or ask an LLM the same question, see if you can make sense of it.

Once the path is correctly setup, you should be able to open a terminal/powershell and type either py --version, python --version, python3 --version and one of those will give you some output. The one that does is the command you will use in the future.

1

u/zeewooly 2d ago

Have done all the Google research with environmental variables and everyone's is different than mine. And done a bunch of research of paths. Also did the setup directly through the website since thats required for the class.

1

u/FoolsSeldom 2d ago

I don't know what you mean by "search it in Command Prompt". Search for what exactly?

How did you install Python on your computer? It is good to confirm it is working correctly from the command line (Command Prompt or Powershell) before trying from your editor.

On a Windows computer, just entering py on its own will start up Python's interactive shell, with a >>> prompt. Enter exit() to leave it. This would show Python is correctly installed.

If you create a simple Python programme using a text editor, or IDLE, which is normally installed alongside Python, you will be able to quickly confirm that things are working with files as well. Save it as hello.py and run using py hello.py.

You can even do this from the Command Prompt:

C:\Users\zeewooly> echo "print('Hello')" > hello.py
C:\Users\zeewooly> py hello.py
Hello
PS C:\Users\zeewooly>

Do you mean Visual Studio or VS (Visual Studio) Code? These are very different products.

1

u/zeewooly 2d ago

I followed the steps in this video given to me by instructor and they didn't work. If search in command prompt is not the right verbiage my bad, again new. https://youtu.be/9o4gDQvVkLU?is=DLZBUrRm1TVZ_3yP

1

u/FoolsSeldom 1d ago

I'm not going to watch the video. Did you try what I suggested? Can you answer the questions I asked you?

1

u/zeewooly 1d ago

I installed python through python.org. When I type py in my command prompt it tells me the version and exit works. I have visual studio code. I also have python extension in VS code. So my now issue is in VS I have test.py and test2.py, saved to my desktop. When I go to command prompt and type py desktop/test.py, it says no such file or directory

1

u/frustratedsignup 1d ago

It sounds like you need to learn how to navigate directories from the command line. Does it work if you run 'py \users\<username>\Desktop\test.py'? You'll need to substitute your account name for <username> in that example.

Note: do not confuse '\' for '/'. They are different and don't behave the same way. I've made an assumption that you are doing this in Windows. Linux/macOS would work a bit differently.

1

u/zeewooly 1d ago

I have figured so much out, thank you very much

1

u/FoolsSeldom 1d ago

It should be Desktop rather than desktop, but Windows isn't generally case-sensitive of folder and filenames, unlike most operating systems (but not a good habit as your code will fail on other systems).

py .\Desktop\hello.py

and

py .\desktop\hello.py

both worked for me.

Are you sure you are in the parent folder of your Desktop? (Likely c:\Users\yourusername\?

Did you try to create and run the hello.py file from the command line as per my example?

Have you "opened a folder" in VS Code?

Personally, I would not save my Python files on the desktop. In fact, I'd create a folder for Python projects in your home folder, perhaps called python_projects. Then, for each project/chapter, I'd create a subfolder and create within that a Python virtual environment:

mkdir python_projects
cd python_projects
mkdir myfirst
cd myfirst
py -m venv .venv
.venv\Scripts\activate

In VS Code, open the folder created above, and hit keys shift + ctrl + P to bring up the Command Palette, enter python and choose Python: Select Interpreter and then pick the python.exe file in the Scripts folder from you project's folder.

1

u/zeewooly 1d ago

I moved all python files to their own folder under c:\ Users\my user name and now when I type up .\assignments\hello.py it opens it in VS. Is that correct? Also I don't understand what youre asking me to do in VS code at the bottom of your reply

1

u/FoolsSeldom 1d ago

It seems you have VS Code setup as your default application for Windows to use to open .py files, which is fine although means you cannot double-click on the files to run them.

In VS Code, explicitly use the menu to open the folder you've called assignments.

The configuration in VS Code was assuming you'd followed my guidance to create a Python virtual environment on a project-by-project basis. I shall add a comment to this one explaining this in more detail.

Were you not able to bring up the Command Palette in VS Code? That is something to learn to use to get the best out of VS Code anyway.

1

u/FoolsSeldom 1d ago

As mentioned ...

Virtual Environments

Given the thousands of packages (libraries, frameworks, etc) out there, you can see that if you are working on several different projects, you can end up installing a vast range of different packages, only a few of which will be used for any particular project.

This is where Python virtual environments come in. Not to be confused with virtual machines. Typically created on a project-by-project basis. Install only the packages required for a project. This helps avoid conflicts between packages, especially version complications.

Most popular code editors and IDEs, including Microsoft's VS Code and JetBrains' PyCharm, offer built-in features to help to start off new projects and create and activate Python virtual environments.

You can create a new Python virtual environment from your operating system command line environment using,

for Windows,

py -m venv .venv

or, for macOS / Linux,

python3 -m venv .venv

Note: venv is a command and .venv is a folder name. You can use any valid folder name instead but this is a common convention.

Often we use .venv instead of venv as the folder name - this may not show up on explorer/folder tools as the leading . is often used to mean hidden and an option may need to be ticked to allow you to see such folders/files

That creates a new folder in the current working directory called .venv.

You then activate using, for Windows,

.venv\Scripts\activate

or, for macOS / Linux,

source .venv/bin/activate

the command deactivate for any platform will deactivate the virtual environment and return you to using the base environment.

You may need to tell your editor to use the Python Interpreter that is found in either the Scripts or bin folder (depending on operating system) in your virtual folder.

Installing packages

Once you've created and activated a Python virtual environment, you can just use the pip something command to install a package, assuming it is in the Pypi respository.

GIT

Latest commit on default branch

pip install git+https://github.com/owner/repo.git

Specific branch, tag, or commit

pip install git+https://github.com/owner/repo.git@branch-name
pip install git+https://github.com/owner/repo.git@v1.2.3
pip install git+https://github.com/owner/repo.git@abcdef1234

If the package lives in a subdirectory of the repo

pip install "git+https://github.com/owner/repo.git#subdirectory=packages/mypkg"

Private repo (SSH, assuming your key is set up)

pip install git+ssh://git@github.com/owner/repo.git

LOCAL

Regular install — copies the package into site-packages

pip install /path/to/local/project

Editable/development install — symlinks back to your source, so changes take effect immediately without reinstalling

pip install -e /path/to/local/project

From the project's own directory

cd /path/to/local/project
pip install -e .

For more information on virtual environments:

Multiple Python versions

In addition to the above, you might want to explore using pyenv (pyenv-win for Windows) or uv (recommended), which will let you install and use different versions of Python including alternative implementations from the reference CPython. This can be done independently of any system installed Python.

1

u/zeewooly 1d ago

Thank you for all of your help. I just ran my first code and it worked.

2

u/FoolsSeldom 1d ago

Excellent. You are on the journey now. Enjoy.