This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: after venv activation "which python3" and sys.path both give base installation instead of venv
Type: behavior Stage: resolved
Components: macOS Versions: Python 3.9
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: dtrodrigues, eric.smith, ned.deily, neeltennis, ronaldoussoren
Priority: normal Keywords:

Created on 2021-02-14 04:36 by neeltennis, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Screen Shot 2021-02-13 at 8.31.20 PM.png neeltennis, 2021-02-14 04:36 Screenshot of terminal commands
Pull Requests
URL Status Linked Edit
PR 24530 open dtrodrigues, 2021-02-15 02:15
Messages (14)
msg386931 - (view) Author: Neel Gore (neeltennis) * Date: 2021-02-14 04:36
Fresh python 3.9.1 installation on macOS, shell is zsh

activated a venv with "python3 -m venv .venv"
activated with "source .venv/bin./activate"

"which python3" and "which pip3" both show my base installation
msg386956 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-02-14 16:20
Please do not post screen captures. It makes it difficult for users with accessibility software and it makes it hard for people trying to help you to copy and paste exactly what you've tried.

I'm unable to duplicate your problem.

[~]$ ps
  PID TTY           TIME CMD
27521 ttys000    0:00.07 -zsh
[~]$ which python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
[~]$ python3 -m venv .venv
[~]$ source .venv/bin/activate
(.venv) [~]$ which python3
/Users/ericsmith/.venv/bin/python3
msg386962 - (view) Author: Dustin Rodrigues (dtrodrigues) * Date: 2021-02-14 21:01
I'm also unable to replicate this. Where did you install Python from? Which version of zsh are you running?
msg386964 - (view) Author: Neel Gore (neeltennis) * Date: 2021-02-14 22:10
zsh 5.8 (x86_64-apple-darwin20.0)
and
macOS Big Sur 11.2.1

This was the normal python dot org installation.
msg386965 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-02-14 22:21
Are you sure there wasn't an existing virtual environment at .venv? By default, venv does not upgrade an existing environment. Try deleting the .venv directory first, assuming there is nothing in the environment you want to save. Otherwise you could try debugging the shell steps with the shell command:

set -x

and, if necessary, debugging the python environment with:

python3 -m test.pythoninfo

https://docs.python.org/3.9/library/venv.html
msg386966 - (view) Author: Neel Gore (neeltennis) * Date: 2021-02-14 22:35
Just ran:

neelgore@Neels-MacBook-Pro Project 4:5 % rm -r .venv
neelgore@Neels-MacBook-Pro Project 4:5 % which python3  
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
neelgore@Neels-MacBook-Pro Project 4:5 % python3 -m venv .venv
neelgore@Neels-MacBook-Pro Project 4:5 % source .venv/bin/activate
(.venv) neelgore@Neels-MacBook-Pro Project 4:5 % which python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
(.venv) neelgore@Neels-MacBook-Pro Project 4:5 %
msg386969 - (view) Author: Neel Gore (neeltennis) * Date: 2021-02-14 22:42
(sorry for double message)
update:

Just created a venv in Desktop and another in a directory in Documents and got the correct behavior both times. Seems like the issue is isolated to the certain directory?
msg386970 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-02-14 22:43
Where did you install Python from?

Before you've activated the virtual env, please run "echo $PATH".

After you've activated the virtual env, can you run "ls -l .venv/bin" and "echo $PATH"?
msg386971 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-02-14 22:46
It could be that the activate is failing for some reason in that directory or terminal session.  Try it in a new terminal session after entering "set -x" so you can see the expanded commands.
msg386972 - (view) Author: Neel Gore (neeltennis) * Date: 2021-02-14 22:54
This is Python 3.9.1 from the normal python.org download.

Before venv activation, "echo $PATH" gives:

/Library/Frameworks/Python.framework/Versions/3.9/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public

After activation, "ls -l .venv/bin" gives:

total 88
-rw-rw-r--  1 neelgore  staff  8834 Feb 14 14:51 Activate.ps1
-rw-rw-r--  1 neelgore  staff  1942 Feb 14 14:51 activate
-rw-rw-r--  1 neelgore  staff   891 Feb 14 14:51 activate.csh
-rw-rw-r--  1 neelgore  staff  2031 Feb 14 14:51 activate.fish
-rwxr-xr-x  1 neelgore  staff   327 Feb 14 14:51 easy_install
-rwxr-xr-x  1 neelgore  staff   327 Feb 14 14:51 easy_install-3.9
-rwxr-xr-x  1 neelgore  staff   318 Feb 14 14:51 pip
-rwxr-xr-x  1 neelgore  staff   318 Feb 14 14:51 pip3
-rwxr-xr-x  1 neelgore  staff   318 Feb 14 14:51 pip3.9
lrwxr-xr-x  1 neelgore  staff     7 Feb 14 14:51 python -> python3
lrwxr-xr-x  1 neelgore  staff    61 Feb 14 14:51 python3 -> /Library/Frameworks/Python.framework/Versions/3.9/bin/python3
lrwxr-xr-x  1 neelgore  staff     7 Feb 14 14:51 python3.9 -> python3

and "echo $PATH" gives:

/Users/neelgore/Documents/UC Irvine/Y1/Q2/ICS 32/Project 4:5/.venv/bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public
msg386973 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-02-14 22:57
Thanks. I’m guessing the space in the path is causing a problem.
msg386974 - (view) Author: Dustin Rodrigues (dtrodrigues) * Date: 2021-02-14 23:07
What's the name of the current directory? Does it end with "Project 4:5"? It may be the colon in the directory name is interfering with the PATH parsing so that the shell thinks that the first two entries in your path after the venv activate are

/Users/neelgore/Documents/UC Irvine/Y1/Q2/ICS 32/Project 4
5/.venv/bin

instead of

"/Users/neelgore/Documents/UC Irvine/Y1/Q2/ICS 32/Project 4:5/.venv/bin"

being the first entry.
msg386975 - (view) Author: Dustin Rodrigues (dtrodrigues) * Date: 2021-02-14 23:17
FWIW, it looks like spaces in directory names in macOS seem to be handled okay in both bash and zsh when working with venv's activate script. Colons do not and there doesn't appear to be a workaround other than not working in a directory with a colon in its name when you want to include that directory in your PATH.
msg386976 - (view) Author: Neel Gore (neeltennis) * Date: 2021-02-14 23:21
Ah in hindsight I see why this was troublesome; the directory name was "Project 4/5", and zsh was displaying the / with a :. Renaming the directory to "Project 4_5" fixed the problem. Thanks everyone!
History
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87384
2021-02-15 02:15:39dtrodriguessetpull_requests: + pull_request23317
2021-02-14 23:23:18ned.deilysetstatus: open -> closed
resolution: works for me
stage: resolved
2021-02-14 23:21:54neeltennissetmessages: + msg386976
2021-02-14 23:17:32dtrodriguessetmessages: + msg386975
2021-02-14 23:07:14dtrodriguessetmessages: + msg386974
2021-02-14 22:57:34eric.smithsetmessages: + msg386973
2021-02-14 22:54:49neeltennissetmessages: + msg386972
2021-02-14 22:46:21ned.deilysetmessages: + msg386971
2021-02-14 22:43:10eric.smithsetmessages: + msg386970
2021-02-14 22:42:59neeltennissetmessages: + msg386969
2021-02-14 22:35:09neeltennissetmessages: + msg386966
2021-02-14 22:21:16ned.deilysetmessages: + msg386965
2021-02-14 22:10:46neeltennissetmessages: + msg386964
2021-02-14 21:01:00dtrodriguessetnosy: + dtrodrigues
messages: + msg386962
2021-02-14 16:20:47eric.smithsetnosy: + eric.smith
messages: + msg386956
2021-02-14 04:36:16neeltenniscreate