Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

after venv activation "which python3" and sys.path both give base installation instead of venv #87384

Closed
neeltennis mannequin opened this issue Feb 14, 2021 · 14 comments
Closed
Labels
3.9 only security fixes OS-mac type-bug An unexpected behavior, bug, or error

Comments

@neeltennis
Copy link
Mannequin

neeltennis mannequin commented Feb 14, 2021

BPO 43218
Nosy @ronaldoussoren, @ericvsmith, @ned-deily, @dtrodrigues
PRs
  • bpo-43218: Prevent venv creation when the target directory contains a PATH separator. (GH-24530) #24530
  • Files
  • Screen Shot 2021-02-13 at 8.31.20 PM.png: Screenshot of terminal commands
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-02-14.23:23:18.247>
    created_at = <Date 2021-02-14.04:36:16.542>
    labels = ['OS-mac', 'type-bug', '3.9']
    title = 'after venv activation "which python3" and sys.path both give base installation instead of venv'
    updated_at = <Date 2021-02-15.02:15:39.687>
    user = 'https://bugs.python.org/neeltennis'

    bugs.python.org fields:

    activity = <Date 2021-02-15.02:15:39.687>
    actor = 'dtrodrigues'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-02-14.23:23:18.247>
    closer = 'ned.deily'
    components = ['macOS']
    creation = <Date 2021-02-14.04:36:16.542>
    creator = 'neeltennis'
    dependencies = []
    files = ['49807']
    hgrepos = []
    issue_num = 43218
    keywords = []
    message_count = 14.0
    messages = ['386931', '386956', '386962', '386964', '386965', '386966', '386969', '386970', '386971', '386972', '386973', '386974', '386975', '386976']
    nosy_count = 5.0
    nosy_names = ['ronaldoussoren', 'eric.smith', 'ned.deily', 'dtrodrigues', 'neeltennis']
    pr_nums = ['24530']
    priority = 'normal'
    resolution = 'works for me'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43218'
    versions = ['Python 3.9']

    @neeltennis
    Copy link
    Mannequin Author

    neeltennis mannequin commented Feb 14, 2021

    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

    @neeltennis neeltennis mannequin added 3.9 only security fixes OS-mac type-bug An unexpected behavior, bug, or error labels Feb 14, 2021
    @ericvsmith
    Copy link
    Member

    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

    @dtrodrigues
    Copy link
    Mannequin

    dtrodrigues mannequin commented Feb 14, 2021

    I'm also unable to replicate this. Where did you install Python from? Which version of zsh are you running?

    @neeltennis
    Copy link
    Mannequin Author

    neeltennis mannequin commented Feb 14, 2021

    zsh 5.8 (x86_64-apple-darwin20.0)
    and
    macOS Big Sur 11.2.1

    This was the normal python dot org installation.

    @ned-deily
    Copy link
    Member

    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

    @neeltennis
    Copy link
    Mannequin Author

    neeltennis mannequin commented Feb 14, 2021

    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 %

    @neeltennis
    Copy link
    Mannequin Author

    neeltennis mannequin commented Feb 14, 2021

    (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?

    @ericvsmith
    Copy link
    Member

    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"?

    @ned-deily
    Copy link
    Member

    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.

    @neeltennis
    Copy link
    Mannequin Author

    neeltennis mannequin commented Feb 14, 2021

    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

    @ericvsmith
    Copy link
    Member

    Thanks. I’m guessing the space in the path is causing a problem.

    @dtrodrigues
    Copy link
    Mannequin

    dtrodrigues mannequin commented Feb 14, 2021

    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.

    @dtrodrigues
    Copy link
    Mannequin

    dtrodrigues mannequin commented Feb 14, 2021

    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.

    @neeltennis
    Copy link
    Mannequin Author

    neeltennis mannequin commented Feb 14, 2021

    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!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes OS-mac type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants