Hi there,
I am new to python etc and I’m trying to do an exercise in Github, part of which is creating a virtual environment locally and importing pandas into Python - I cannot get Python to point to the file path where the pandas are, even though I have used the suggested commands for pip install to force python to look at the project folder virtual environment; the python.exe and pip.exe are both in the project folder as are the pandas but whenever I run "import sys; print(sys.executable) in Python, it brings back the global file path in the general Program Files - I have exhausted chatGPT, it’s just in circles now trying to fix it!! Any ideas please??
Have you activated the venv?
Yes I have, (.myenv) prefixes the commands
Do you have more than one version of Python
installed? If you do, this might be the issue. Note that every Python
installation has its own ecosystem environment. As an example, if you have v3.9
and v3.13
installed, and if you pip
install Pandas
for say v3.9
, it will not be visible to v3.13
. They’re separate. If this is the case, make sure you’re opening the “correct
” version of Python
for your project.
This may or may not be the issue for your particular case but may be worth looking into for verification.
Edit:
To check which Python
version Pandas
was installed to, in the terminal window, type the following:
C:\> python -V
Python 3.13.0
C:\> python -c "import pandas; print(pandas.__file__)"
C:\Users\my_folder\AppData\Roaming\Python\Python313\site-packages\pandas\__init__.py
You should see something similar to this on your system. Note that the Pandas
library package path matches the Python
version currently running on my system. You should see something similar to this.
I haven’t heard of .myenv
before. Is it this? I’m not sure that can activate venvs, as it won’t kick in until after Python is already launched.
Assuming the installation of pandas with pip was successful, I suspect the basic problem anyway, is that pandas etc. were installed into a different Python to the “Python” being run. Either a different venv or global env, or as Paul says, a different version of Python entirely that’s also installed.
‘.myenv’ is probably just the name of the venv directory.
~$ python -m venv .myvenv
~$ source .myvenv/bin/activate
(.myvenv) ~$