Python Forum
pip installs in a different python version and directory than the default 3.11
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pip installs in a different python version and directory than the default 3.11
#1
Hi All,

Quick question - not related explicitly to python code - more related to installing packages.

When I try to install packages with pip install - by default it gets installed to Python 3.10 site-packages location as below, notice the python310 directory.
PS C:\Users\abhik\Nextcloud\Python\Desktop> pip install lxml      
Requirement already satisfied: lxml in c:\users\abhik\appdata\local\programs\python\python310\lib\site-packages (4.9.2)
However my default python version is python 311 and the environment variables have 3.11 paths first in order.
PS C:\Users\abhik\Nextcloud\Python\Desktop> py -V 
Python 3.11.4
[Image: 2023-06-18-11-43-30-Settings.png]

So first question is - why is that happening and how do I change that behavior? I want pip to install packages to 311 directory by default without having to specify the target every time. I thought the PATH variable being defined and set int he right order should achieve that.

Second question is that if I do force the package to be installed in 3.11 by using py -m pip install it does work but even after that when I execute the code with 3.11 as the interpreter it produces an error saying the package is not installed. Code works as intended on 3.10.

PS C:\Users\abhik\Nextcloud\Python\Desktop> py -m pip install lxml     
Requirement already satisfied: lxml in c:\users\abhik\appdata\local\programs\python\python311\lib\site-packages (4.9.2)
I am using VS Code with Jupyter extensions, here is a sample of the error (not full code).
[Image: 2023-06-18-12-24-09-python-automations-p...o-Code.png]

I checked the 3.11 site-packages directory to make sure it is installed and it is. Not sure why the code still won't run on 3.11

All help appreciated.
Thanks in advance.
Reply
#2
(Jun-18-2023, 05:19 PM)ao_tex_mal Wrote: So first question is - why is that happening and how do I change that behavior? I want pip to install packages to 311 directory by default without having to specify the target every time. I thought the PATH variable being defined and set int he right order should achieve that.
No,if you want to use Python 3.11 as default you delete all other paths in Environment Variables(System Variables).
Then use can py to acesss older versions,it will find most that installed.
G:\div_code
λ py --list
 -V:3.11 *        Python 3.11 (64-bit)
 -V:3.10          Python 3.10 (64-bit)
 -V:3.9           Python 3.9 (64-bit)
 -V:3.8           Python 3.8 (64-bit)
 -V:3.7-32        Python 3.7 (32-bit)
 -V:3.6-32        Python 3.6 (32-bit)
 -V:3.5-32
 -V:3.4
 -V:2.7
 -V:2.1
 -V:ContinuumAnalytics/Anaconda39-64 Anaconda py39_4.9.2
 -V:ContinuumAnalytics/Anaconda37-64 Anaconda 4.7.12
 -V:ContinuumAnalytics/Anaconda36-32 Anaconda 4.3.14

# If i want use Python 3.9 it would be like this
G:\div_code
λ py -3.9 hello.py
hello world

# Install a package to eg 3.6
G:\div_code
λ py -3.6 -m pip install requests

# I have set Python 3.11 in Path
G:\div_code
λ python -V
Python 3.11.3

G:\div_code
λ pip -V
pip 23.1.2 from C:\python311\Lib\site-packages\pip (python 3.11)

# py alone always use lastet version
G:\div_code
λ py -V
Python 3.11.3
Reply
#3
(Jun-18-2023, 06:51 PM)snippsat Wrote: No,if you want to use Python 3.11 as default you delete all other paths in Environment Variables(System Variables).
Thanks for the response.

I deleted all the other paths from the PATH environment variable except for Python311 and Python311\Scripts and restarted the machine.

Tried pip install after restarting and it is still going to Python310 by default.

So that did not work.
Reply
#4
(Jun-19-2023, 12:31 PM)ao_tex_mal Wrote: I deleted all the other paths from the PATH environment variable except for Python311 and Python311\Scripts and restarted the machine.

Tried pip install after restarting and it is still going to Python310 by default.
How to Edit Your System PATH for Easy Command Line Access in Windows
So under System Variabels you add Path to Python311 and Python311\Scripts full paths.
Check also that no path is in Users Varables Path,then try again.

If still problem use where python or python -c "import sys; print(sys.executable)" to see what path are.
G:\div_code
λ where python
C:\python311\python.exe
C:\Documents and Settings\Tom\.rye\shims\python.exe

# Now only point to path that <python> use.
G:\div_code
λ python -c "import sys; print(sys.executable)"
C:\python311\python.exe

# Same with <pip> should have same root path
G:\div_code
λ pip -V
pip 23.1.2 from C:\python311\Lib\site-packages\pip (python 3.11)
Reply
#5
Yes both User Variables and System Variables for PATH has been edited to remove everything except Python311 paths.
Still pip goes to Python310 by default, not sure why.

[Image: Screenshot-2023-06-19-082111.png]
Reply
#6
I guess this install correct python -m pip install lxml.
G:\div_code\hex
λ python -m pip install lxml
Requirement already satisfied: lxml in c:\python311\lib\site-packages (4.9.2)
Check from command line(cmd) echo %Path% (System) and echo %Path% (Users),
that path to Scripts folder is corrcet and that it only has Python 3.11.
Reply
#7
(Jun-19-2023, 01:52 PM)snippsat Wrote: Check from command line(cmd) echo %Path% (System) and echo %Path% (Users),
that path to Scripts folder is corrcet and that it only has Python 3.11.

Yes to both.

[Image: Screenshot-2023-06-19-092145.png]
Reply
#8
Something is strange here.
Can do eg.
G:\div_code
λ where pip
C:\python311\Scripts\pip.exe

G:\div_code
λ pip -V
pip 23.1.2 from C:\python311\Lib\site-packages\pip (python 3.11)
Thern just delete the wrong Path in file system,and see if update to correct path to pip.

Can go into register(regedit) and look if it is correct there.
# System
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session

# User
HKEY_CURRENT_USER\Environment
Both is under key Path --> REG_EXPAND_SZ

Of course both this work and use corrct pip,if can not get pip alone to for some strange reason.
py -m pip install lxml 
python -m pip install lxml 
Reply
#9
Yeah agreed very strange. Everything looks right.

Registry Keys were all set as it is shown in the cli and GUI output. Local Machine key is in
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
But pip still is being executed from the wrong folder and packages being stored in the wrong location.
PS C:\Users\abhik\Nextcloud\Python\Desktop\Python Models> pip -V
pip 23.1.2 from C:\Users\abhik\AppData\Local\Programs\Python\Python310\lib\site-packages\pip (python 3.10)
I am thinking the only way to solve this is to uninstall 3.10 and try. I will have to reinstall it later. Any other thoughts?
Reply
#10
(Jun-20-2023, 01:49 PM)ao_tex_mal Wrote: I am thinking the only way to solve this is to uninstall 3.10 and try. I will have to reinstall it later. Any other thoughts?
Yes uninstall,and also go in File Explorer to make sure that all is gone,Restart after.
The default folder that Python install to AppData\Local... is hidden bye deafult,
so go to the View tab at the top and check the Hidden items and File Name Extensions to see all.

I never use the default path when install Python,so i simplly has under root C:\.
I undestand the security reason why Windows place it a folder fair away👀,but i don't care abot that.
G:\div_code
λ where python
C:\python311\python.exe

G:\div_code
λ pip -V
pip 23.1.2 from C:\python311\Lib\site-packages\pip (python 3.11)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  run part of a script with a different version of Python jdog 2 463 Jan-09-2024, 08:49 PM
Last Post: jdog
  How to find out from outside Python (in Windows) the current version of Python? pstein 4 754 Oct-04-2023, 10:01 AM
Last Post: snippsat
  How to resolve version conflicts in Python? taeefnajib 0 937 Apr-27-2023, 08:37 PM
Last Post: taeefnajib
  create a default path with idle to a specific directory greybill 0 882 Apr-23-2023, 04:32 AM
Last Post: greybill
  Python venv and PIP version issue JanOlvegg 2 1,281 Feb-22-2023, 02:22 AM
Last Post: JanOlvegg
  Python Version upgrade nitinkukreja 1 913 Feb-04-2023, 10:27 PM
Last Post: Larz60+
  Mac default python interpreter Viewpoint8455 2 931 Oct-13-2022, 06:25 AM
Last Post: perfringo
  Can't update new python version on Pycharm GOKUUUU 6 3,871 Jul-23-2022, 09:24 PM
Last Post: GOKUUUU
  Building python (3.9.5) with different libexpat version (2.4.6) raghupcr 0 1,321 Feb-25-2022, 11:29 AM
Last Post: raghupcr
  Python keeps running the old version of the code quest 2 3,789 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020