I’m fairly new to Python. I use Python 3.11.8 (what MS Azure supports, my eventual production environment) on Windows 10.
I’m testing a program on Windows 10.
I have created and activated my virtual environment in the cmd.exe window.
My program is in c:\users\MYUSER\onedrive - CONAME\documents\pythonprojects\CONAME\CUSTNAME\buscard\buscard.py
This program worked last week just fine. The only thing that changed is at the top of the program, I changed the order of imports to make importing my custom utils (call it ggutils.py) last as I may have to change the sys.path right before I import ggutils. But the error happens before I change the sys.path.
Imports of standard modules work fine. Pandas has to be installed separately. That’s the one that fails.
I edit my program in VS Code but run it in cmd.exe with the command line: py -m pdb buscard.py input "Test 1"
Here is my code:
import os
import re
import sys
print("Sys.path is:",sys.path)
import glob # To get list of files.
import inspect
from pathlib import Path
import pandas # NOT FOUND
import shutil
import xmltodict
sys.path.append(sys.path[0] + r"c:\users\MYUSER\Pycharmprojects\ggutil2024") # Required to use ggutil
from ggutil import * # My Custom utils.
When I run my buscard.py program and I get to a line import pandas then I get an error “Module not found”. When I go to cmd.exe and run pip install pandas I get “Requirements already satisfied”.
I’m not sure what I’m doing wrong here. I ran the program the same way last week via cmd.exe and it worked fine.
Got pip installed. This works for Python 3.11: py -m ensurepip --upgrade
The command is now pip3 not pip. It was installed in C:\Users\MYUSER\AppData\Local\Programs\Python\Python311\Scripts so make sure your path points to there.
I will put updates below in this message:
Program seems to be working now. I will test my custom utils file now.
Are you generally familiar with why this is done or would you be interested in an overview?
In Python 3.9 I used pip. But in Python 3.11 it was renamed to pip3. In a tutorial I saw that was done on a Mac he also used pip3 for Python 3.x. I’d be interested to know why.
There are two worlds of python commands Windows and the rest, macOS and Unix.
On Windows its been a matter of changing the PATH to point at the version of python, and its tools like pip, that you want to use. If you look in the Scripts folder you will see that python3.12, for example, has pip.exe, pip3.exe and pip3.12.exe.
However after the py command was added there is a more robust way. Use py to start python and py -m pip to start pip.
If you install more then one version of python on Windows you can run the exact version you want using py -3.10 and py -3.12. To run the matching pip you can use py -3.10 -m pip. This avoids the need to change the PATH.
On the rest, macOS and Unix, python installs with multiple names.
For example for python 3.12 there will be python3.12 and, often, python3 as a symlink to python3.12.
If you install multiple versions of python then you would have python3.10 etc.
The same naming is done for pip versions that match python versions. pip3.12, pip3.10 and pip3 as a symlink to one of them.
Lastly why is pip called pip3? Becuase of python 2 already using the pip name.