Consequences for virtual env when system's Python is removed and/or updated2019 Community Moderator ElectionHow can I remove a trailing newline in Python?How do I remove an element from a list by index in Python?Why do people write the #!/usr/bin/env python shebang on the first line of a Python script?How to remove a key from a Python dictionary?How to upgrade virtual environment from previous Python version?virtual env python 3.5 only finds django python 2.7Python version in virtualenv - ubuntu 16.04UnicodeDecodeError during plot.show() in python virtual environmentHow to install python3.7 and create a virtualenv with pip on Ubuntu 18.04?How to execute virtualenv from /Library/Frameworks/Python.framework/Versions/.. in Mac

Are small insurances worth it?

Having the player face themselves after the mid-game

Why do we say 'Pairwise Disjoint', rather than 'Disjoint'?

Unfamiliar notation in Diabelli's "Duet in D" for piano

What the error in writing this equation by latex?

How to recover against Snake as a heavyweight character?

Book where society has been split into 2 with a wall down the middle where one side embraced high tech whereas other side were totally against tech

Draw this image in the TIKZ package

Create chunks from an array

Why would /etc/passwd be used every time someone executes `ls -l` command?

The (Easy) Road to Code

Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?

If nine coins are tossed, what is the probability that the number of heads is even?

What is Tony Stark injecting into himself in Iron Man 3?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Unidentified signals on FT8 frequencies

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

Why does this boat have a landing pad? (SpaceX's GO Searcher) Any plans for propulsive capsule landings?

What is better: yes / no radio, or simple checkbox?

Why restrict private health insurance?

Tabular environment - text vertically positions itself by bottom of tikz picture in adjacent cell

How would an energy-based "projectile" blow up a spaceship?

Rationale to prefer local variables over instance variables?

Does the US political system, in principle, allow for a no-party system?



Consequences for virtual env when system's Python is removed and/or updated



2019 Community Moderator ElectionHow can I remove a trailing newline in Python?How do I remove an element from a list by index in Python?Why do people write the #!/usr/bin/env python shebang on the first line of a Python script?How to remove a key from a Python dictionary?How to upgrade virtual environment from previous Python version?virtual env python 3.5 only finds django python 2.7Python version in virtualenv - ubuntu 16.04UnicodeDecodeError during plot.show() in python virtual environmentHow to install python3.7 and create a virtualenv with pip on Ubuntu 18.04?How to execute virtualenv from /Library/Frameworks/Python.framework/Versions/.. in Mac










7















EDIT FOR CLARITY: This question is in reference to venv, which is often confused with virtualenv.



What are the consequences of removing the system's Python installation which was the source used to create virtual environments on the system using venv?



Ultimately, what I'm looking to do is remove the 3.7 installation and install 3.8 when it is released, but I'm unsure of how strongly tethered a virtual environment is to the system environment.



Some system details that may be relevant when asking this question:



  • OS = Red Hat Enterprise Linux 7

  • 3.7 installed from source at Python.org, not the rh-Pythonx.x packge in the yum repo.

  • Python 3.7 is installed to the default location, /usr/local/bin/python3.7


  • /usr/local/bin/python3 is a link to /usr/local/bin/python3.7

Given the above details, I am under the impression that Python 3.8 would install to /usr/local/bin/python3.8 and python3 would then be pointing to that version.



Does the virtual environment have enough within it to be a stable 3.7 environment of its own? Or will it fall apart, trying to reference a system install that no longer exists?



tl;dr:
What happens to all those virtual environments that were created from a Python source that is no longer existent / replaced with a newer version?










share|improve this question



















  • 1





    Note that you can safely install multiple versions of Python side by side. There is no technical reason to remove your Python 3.7 installation before installing 3.8.

    – Code-Apprentice
    2 days ago











  • @Code-Apprentice: Well, depends on how you install it. I'd strongly recommend using make altinstall when installing 3.8 from source, so the system default python3 remains whatever shipped with the OS and any scripts shipped with the OS that have python3 dependencies don't suddenly have Python upgraded under them in a potentially breaking way (it's rare, but there are scripts/modules that depend on internals of a given minor release and break in subsequent releases).

    – ShadowRanger
    2 days ago















7















EDIT FOR CLARITY: This question is in reference to venv, which is often confused with virtualenv.



What are the consequences of removing the system's Python installation which was the source used to create virtual environments on the system using venv?



Ultimately, what I'm looking to do is remove the 3.7 installation and install 3.8 when it is released, but I'm unsure of how strongly tethered a virtual environment is to the system environment.



Some system details that may be relevant when asking this question:



  • OS = Red Hat Enterprise Linux 7

  • 3.7 installed from source at Python.org, not the rh-Pythonx.x packge in the yum repo.

  • Python 3.7 is installed to the default location, /usr/local/bin/python3.7


  • /usr/local/bin/python3 is a link to /usr/local/bin/python3.7

Given the above details, I am under the impression that Python 3.8 would install to /usr/local/bin/python3.8 and python3 would then be pointing to that version.



Does the virtual environment have enough within it to be a stable 3.7 environment of its own? Or will it fall apart, trying to reference a system install that no longer exists?



tl;dr:
What happens to all those virtual environments that were created from a Python source that is no longer existent / replaced with a newer version?










share|improve this question



















  • 1





    Note that you can safely install multiple versions of Python side by side. There is no technical reason to remove your Python 3.7 installation before installing 3.8.

    – Code-Apprentice
    2 days ago











  • @Code-Apprentice: Well, depends on how you install it. I'd strongly recommend using make altinstall when installing 3.8 from source, so the system default python3 remains whatever shipped with the OS and any scripts shipped with the OS that have python3 dependencies don't suddenly have Python upgraded under them in a potentially breaking way (it's rare, but there are scripts/modules that depend on internals of a given minor release and break in subsequent releases).

    – ShadowRanger
    2 days ago













7












7








7








EDIT FOR CLARITY: This question is in reference to venv, which is often confused with virtualenv.



What are the consequences of removing the system's Python installation which was the source used to create virtual environments on the system using venv?



Ultimately, what I'm looking to do is remove the 3.7 installation and install 3.8 when it is released, but I'm unsure of how strongly tethered a virtual environment is to the system environment.



Some system details that may be relevant when asking this question:



  • OS = Red Hat Enterprise Linux 7

  • 3.7 installed from source at Python.org, not the rh-Pythonx.x packge in the yum repo.

  • Python 3.7 is installed to the default location, /usr/local/bin/python3.7


  • /usr/local/bin/python3 is a link to /usr/local/bin/python3.7

Given the above details, I am under the impression that Python 3.8 would install to /usr/local/bin/python3.8 and python3 would then be pointing to that version.



Does the virtual environment have enough within it to be a stable 3.7 environment of its own? Or will it fall apart, trying to reference a system install that no longer exists?



tl;dr:
What happens to all those virtual environments that were created from a Python source that is no longer existent / replaced with a newer version?










share|improve this question
















EDIT FOR CLARITY: This question is in reference to venv, which is often confused with virtualenv.



What are the consequences of removing the system's Python installation which was the source used to create virtual environments on the system using venv?



Ultimately, what I'm looking to do is remove the 3.7 installation and install 3.8 when it is released, but I'm unsure of how strongly tethered a virtual environment is to the system environment.



Some system details that may be relevant when asking this question:



  • OS = Red Hat Enterprise Linux 7

  • 3.7 installed from source at Python.org, not the rh-Pythonx.x packge in the yum repo.

  • Python 3.7 is installed to the default location, /usr/local/bin/python3.7


  • /usr/local/bin/python3 is a link to /usr/local/bin/python3.7

Given the above details, I am under the impression that Python 3.8 would install to /usr/local/bin/python3.8 and python3 would then be pointing to that version.



Does the virtual environment have enough within it to be a stable 3.7 environment of its own? Or will it fall apart, trying to reference a system install that no longer exists?



tl;dr:
What happens to all those virtual environments that were created from a Python source that is no longer existent / replaced with a newer version?







python upgrade python-venv virtual-environment






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







Joshua Schlichting

















asked 2 days ago









Joshua SchlichtingJoshua Schlichting

1,0731124




1,0731124







  • 1





    Note that you can safely install multiple versions of Python side by side. There is no technical reason to remove your Python 3.7 installation before installing 3.8.

    – Code-Apprentice
    2 days ago











  • @Code-Apprentice: Well, depends on how you install it. I'd strongly recommend using make altinstall when installing 3.8 from source, so the system default python3 remains whatever shipped with the OS and any scripts shipped with the OS that have python3 dependencies don't suddenly have Python upgraded under them in a potentially breaking way (it's rare, but there are scripts/modules that depend on internals of a given minor release and break in subsequent releases).

    – ShadowRanger
    2 days ago












  • 1





    Note that you can safely install multiple versions of Python side by side. There is no technical reason to remove your Python 3.7 installation before installing 3.8.

    – Code-Apprentice
    2 days ago











  • @Code-Apprentice: Well, depends on how you install it. I'd strongly recommend using make altinstall when installing 3.8 from source, so the system default python3 remains whatever shipped with the OS and any scripts shipped with the OS that have python3 dependencies don't suddenly have Python upgraded under them in a potentially breaking way (it's rare, but there are scripts/modules that depend on internals of a given minor release and break in subsequent releases).

    – ShadowRanger
    2 days ago







1




1





Note that you can safely install multiple versions of Python side by side. There is no technical reason to remove your Python 3.7 installation before installing 3.8.

– Code-Apprentice
2 days ago





Note that you can safely install multiple versions of Python side by side. There is no technical reason to remove your Python 3.7 installation before installing 3.8.

– Code-Apprentice
2 days ago













@Code-Apprentice: Well, depends on how you install it. I'd strongly recommend using make altinstall when installing 3.8 from source, so the system default python3 remains whatever shipped with the OS and any scripts shipped with the OS that have python3 dependencies don't suddenly have Python upgraded under them in a potentially breaking way (it's rare, but there are scripts/modules that depend on internals of a given minor release and break in subsequent releases).

– ShadowRanger
2 days ago





@Code-Apprentice: Well, depends on how you install it. I'd strongly recommend using make altinstall when installing 3.8 from source, so the system default python3 remains whatever shipped with the OS and any scripts shipped with the OS that have python3 dependencies don't suddenly have Python upgraded under them in a potentially breaking way (it's rare, but there are scripts/modules that depend on internals of a given minor release and break in subsequent releases).

– ShadowRanger
2 days ago












2 Answers
2






active

oldest

votes


















2














Bad news: You're using venv, and venv virtual environments are not completely standalone. Even when created with --copies, all it copies is the python executable itself, not the standard libraries, not even (if your install creates a shared libpython rather than a static one) libpython; it relies on the system copy. The virtual environment will break if the Python install it was based on goes away. How it breaks will differ based on how it was created. For example, if you created it with:



python3 -mvenv path/to/venv


when python3 meant Python 3.7, then replaced python3 with Python 3.8, then you can fix up the virtual env for the new version with:



python3 -mvenv --upgrade path/to/venv


but your installed third party packages will be (effectively) gone (they'll be in path/to/venv/lib/python3.7, but Python 3.8 will only be looking in path/to/venv/lib/python3.8), so you'll have to reinstall them.



If you created the virtual environment with:



python3.7 -mvenv path/to/venv


then it's completely broken (at least as documented), the --upgrade switch is only documented to work for upgrading when Python was upgraded in place; since the new Python would not be named python3.7, you can't upgrade in place. That said, --upgrade really only works well when upgrading micro versions (from 3.7.1 to 3.7.2 or the like), due to aforementioned per-minor version lib/pythonX.Y directories, so either way, you're best off just creating a new virtual environment from scratch.



To be clear, the third party virtualenv package does not have this limitation if and only if the system Python installation statically linked libpython. Oddly, while the --always-copy flag will make it copy the main binary and the standard library modules, it doesn't cause libpython itself (the interpreter core) to be copied, so if the main binary depends on a system copy of libpython.so, then removing the system copy breaks the virtual environment. If you did use --always-copy and your python executable statically linked libpython.a (ldd /path/to/python3 should show no libpython dependency), then yes, virtualenv makes much more heavyweight (in local tests on 3.6, forcing copies via the appropriate switch, freshly created venv environments were ~11 MB, while virtualenv environments were ~48 MB; sadly, my python dynamically links libpython.so, so it still wouldn't work) virtual environments that should survive the removal of the system installed copy of Python.



In any event, it's probably best to leave your Python 3.7 install in place, and just upgrade to 3.8 without removing 3.7 (are you really hard up for a few dozen MB of disk space?). Even if you replace python3 with the new 3.8 install, python3.7, libpython3.7m.so.1.0 or the like and the rest of the 3.7 standard library will continue to exist for the virtual environment to depend on; at worst you might need to manually change the symlink in the virtual environment to point to /path/to/python3.7 rather than /path/to/python3 to keep using the old version (including all your installed third party packages).



An alternative to trying to keep the old virtual environment working is to just back up the installed state of that virtual environment, delete it, install the new Python, create a fresh virtual environment, and then use the backed up state to reinstall all your packages in the upgraded virtual env. An example might be:



$ source ~/path/to/venv/bin/activate
$ pip freeze > installed_libs.txt
$ deactivate
$ rm -rf ~/path/to/venv
$ ... install new Python/remove old Python ...
$ python3 -mvenv ~/path/to/venv
$ pip install -r installed_libs.txt # Optionally add --upgrade to install latest, not fixed versions





share|improve this answer
































    1














    A virtualenv includes a copy of the python binary itself, so nothing should happen. See a more detailed explanation here




    virtualenv solves this problem by creating a completely isolated virtual environment for each of your programs. An environment is simply a directory that contains a complete copy of everything needed to run a Python program, including a copy of the python binary itself, a copy of the entire Python standard library, a copy of the pip installer, and (crucially) a copy of the site-packages directory mentioned above. When you install a package from PyPI using the copy of pip that's created by the virtualenv tool, it will install the package into the site-packages directory inside the virtualenv directory. You can then use it in your program just as before.




    Edit (accounting for venv vs virtualenv): According to the venv-documentation, it can either copy or symlink the binary:




    The venv module provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories. Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.







    share|improve this answer




















    • 3





      It should be noted for anyone reading this that while venv and virtualenv are similar, they are not the same package.

      – Joshua Schlichting
      2 days ago











    • Good point, edited the answer accordingly

      – dorvak
      2 days ago











    • This answer says a completely different thing than the other answers to this question, namely that it does not break when updating the system python, because it can copy it

      – Ferrybig
      2 days ago











    • @Ferrybig: That's because virtualenv (third party package) and venv (built-in part of Python standard library) behave differently. This answer was originally answered from the perspective of virtualenv (they missed the OP saying they used venv). As it happens, virtualenv still isn't guaranteed to work if the system Python goes away since libpython.so isn't copied (which seems like a bug in virtualenv, given its guarantees about standalone behavior), but it has a chance to work, where venv definitely won't.

      – ShadowRanger
      2 days ago










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55025873%2fconsequences-for-virtual-env-when-systems-python-is-removed-and-or-updated%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Bad news: You're using venv, and venv virtual environments are not completely standalone. Even when created with --copies, all it copies is the python executable itself, not the standard libraries, not even (if your install creates a shared libpython rather than a static one) libpython; it relies on the system copy. The virtual environment will break if the Python install it was based on goes away. How it breaks will differ based on how it was created. For example, if you created it with:



    python3 -mvenv path/to/venv


    when python3 meant Python 3.7, then replaced python3 with Python 3.8, then you can fix up the virtual env for the new version with:



    python3 -mvenv --upgrade path/to/venv


    but your installed third party packages will be (effectively) gone (they'll be in path/to/venv/lib/python3.7, but Python 3.8 will only be looking in path/to/venv/lib/python3.8), so you'll have to reinstall them.



    If you created the virtual environment with:



    python3.7 -mvenv path/to/venv


    then it's completely broken (at least as documented), the --upgrade switch is only documented to work for upgrading when Python was upgraded in place; since the new Python would not be named python3.7, you can't upgrade in place. That said, --upgrade really only works well when upgrading micro versions (from 3.7.1 to 3.7.2 or the like), due to aforementioned per-minor version lib/pythonX.Y directories, so either way, you're best off just creating a new virtual environment from scratch.



    To be clear, the third party virtualenv package does not have this limitation if and only if the system Python installation statically linked libpython. Oddly, while the --always-copy flag will make it copy the main binary and the standard library modules, it doesn't cause libpython itself (the interpreter core) to be copied, so if the main binary depends on a system copy of libpython.so, then removing the system copy breaks the virtual environment. If you did use --always-copy and your python executable statically linked libpython.a (ldd /path/to/python3 should show no libpython dependency), then yes, virtualenv makes much more heavyweight (in local tests on 3.6, forcing copies via the appropriate switch, freshly created venv environments were ~11 MB, while virtualenv environments were ~48 MB; sadly, my python dynamically links libpython.so, so it still wouldn't work) virtual environments that should survive the removal of the system installed copy of Python.



    In any event, it's probably best to leave your Python 3.7 install in place, and just upgrade to 3.8 without removing 3.7 (are you really hard up for a few dozen MB of disk space?). Even if you replace python3 with the new 3.8 install, python3.7, libpython3.7m.so.1.0 or the like and the rest of the 3.7 standard library will continue to exist for the virtual environment to depend on; at worst you might need to manually change the symlink in the virtual environment to point to /path/to/python3.7 rather than /path/to/python3 to keep using the old version (including all your installed third party packages).



    An alternative to trying to keep the old virtual environment working is to just back up the installed state of that virtual environment, delete it, install the new Python, create a fresh virtual environment, and then use the backed up state to reinstall all your packages in the upgraded virtual env. An example might be:



    $ source ~/path/to/venv/bin/activate
    $ pip freeze > installed_libs.txt
    $ deactivate
    $ rm -rf ~/path/to/venv
    $ ... install new Python/remove old Python ...
    $ python3 -mvenv ~/path/to/venv
    $ pip install -r installed_libs.txt # Optionally add --upgrade to install latest, not fixed versions





    share|improve this answer





























      2














      Bad news: You're using venv, and venv virtual environments are not completely standalone. Even when created with --copies, all it copies is the python executable itself, not the standard libraries, not even (if your install creates a shared libpython rather than a static one) libpython; it relies on the system copy. The virtual environment will break if the Python install it was based on goes away. How it breaks will differ based on how it was created. For example, if you created it with:



      python3 -mvenv path/to/venv


      when python3 meant Python 3.7, then replaced python3 with Python 3.8, then you can fix up the virtual env for the new version with:



      python3 -mvenv --upgrade path/to/venv


      but your installed third party packages will be (effectively) gone (they'll be in path/to/venv/lib/python3.7, but Python 3.8 will only be looking in path/to/venv/lib/python3.8), so you'll have to reinstall them.



      If you created the virtual environment with:



      python3.7 -mvenv path/to/venv


      then it's completely broken (at least as documented), the --upgrade switch is only documented to work for upgrading when Python was upgraded in place; since the new Python would not be named python3.7, you can't upgrade in place. That said, --upgrade really only works well when upgrading micro versions (from 3.7.1 to 3.7.2 or the like), due to aforementioned per-minor version lib/pythonX.Y directories, so either way, you're best off just creating a new virtual environment from scratch.



      To be clear, the third party virtualenv package does not have this limitation if and only if the system Python installation statically linked libpython. Oddly, while the --always-copy flag will make it copy the main binary and the standard library modules, it doesn't cause libpython itself (the interpreter core) to be copied, so if the main binary depends on a system copy of libpython.so, then removing the system copy breaks the virtual environment. If you did use --always-copy and your python executable statically linked libpython.a (ldd /path/to/python3 should show no libpython dependency), then yes, virtualenv makes much more heavyweight (in local tests on 3.6, forcing copies via the appropriate switch, freshly created venv environments were ~11 MB, while virtualenv environments were ~48 MB; sadly, my python dynamically links libpython.so, so it still wouldn't work) virtual environments that should survive the removal of the system installed copy of Python.



      In any event, it's probably best to leave your Python 3.7 install in place, and just upgrade to 3.8 without removing 3.7 (are you really hard up for a few dozen MB of disk space?). Even if you replace python3 with the new 3.8 install, python3.7, libpython3.7m.so.1.0 or the like and the rest of the 3.7 standard library will continue to exist for the virtual environment to depend on; at worst you might need to manually change the symlink in the virtual environment to point to /path/to/python3.7 rather than /path/to/python3 to keep using the old version (including all your installed third party packages).



      An alternative to trying to keep the old virtual environment working is to just back up the installed state of that virtual environment, delete it, install the new Python, create a fresh virtual environment, and then use the backed up state to reinstall all your packages in the upgraded virtual env. An example might be:



      $ source ~/path/to/venv/bin/activate
      $ pip freeze > installed_libs.txt
      $ deactivate
      $ rm -rf ~/path/to/venv
      $ ... install new Python/remove old Python ...
      $ python3 -mvenv ~/path/to/venv
      $ pip install -r installed_libs.txt # Optionally add --upgrade to install latest, not fixed versions





      share|improve this answer



























        2












        2








        2







        Bad news: You're using venv, and venv virtual environments are not completely standalone. Even when created with --copies, all it copies is the python executable itself, not the standard libraries, not even (if your install creates a shared libpython rather than a static one) libpython; it relies on the system copy. The virtual environment will break if the Python install it was based on goes away. How it breaks will differ based on how it was created. For example, if you created it with:



        python3 -mvenv path/to/venv


        when python3 meant Python 3.7, then replaced python3 with Python 3.8, then you can fix up the virtual env for the new version with:



        python3 -mvenv --upgrade path/to/venv


        but your installed third party packages will be (effectively) gone (they'll be in path/to/venv/lib/python3.7, but Python 3.8 will only be looking in path/to/venv/lib/python3.8), so you'll have to reinstall them.



        If you created the virtual environment with:



        python3.7 -mvenv path/to/venv


        then it's completely broken (at least as documented), the --upgrade switch is only documented to work for upgrading when Python was upgraded in place; since the new Python would not be named python3.7, you can't upgrade in place. That said, --upgrade really only works well when upgrading micro versions (from 3.7.1 to 3.7.2 or the like), due to aforementioned per-minor version lib/pythonX.Y directories, so either way, you're best off just creating a new virtual environment from scratch.



        To be clear, the third party virtualenv package does not have this limitation if and only if the system Python installation statically linked libpython. Oddly, while the --always-copy flag will make it copy the main binary and the standard library modules, it doesn't cause libpython itself (the interpreter core) to be copied, so if the main binary depends on a system copy of libpython.so, then removing the system copy breaks the virtual environment. If you did use --always-copy and your python executable statically linked libpython.a (ldd /path/to/python3 should show no libpython dependency), then yes, virtualenv makes much more heavyweight (in local tests on 3.6, forcing copies via the appropriate switch, freshly created venv environments were ~11 MB, while virtualenv environments were ~48 MB; sadly, my python dynamically links libpython.so, so it still wouldn't work) virtual environments that should survive the removal of the system installed copy of Python.



        In any event, it's probably best to leave your Python 3.7 install in place, and just upgrade to 3.8 without removing 3.7 (are you really hard up for a few dozen MB of disk space?). Even if you replace python3 with the new 3.8 install, python3.7, libpython3.7m.so.1.0 or the like and the rest of the 3.7 standard library will continue to exist for the virtual environment to depend on; at worst you might need to manually change the symlink in the virtual environment to point to /path/to/python3.7 rather than /path/to/python3 to keep using the old version (including all your installed third party packages).



        An alternative to trying to keep the old virtual environment working is to just back up the installed state of that virtual environment, delete it, install the new Python, create a fresh virtual environment, and then use the backed up state to reinstall all your packages in the upgraded virtual env. An example might be:



        $ source ~/path/to/venv/bin/activate
        $ pip freeze > installed_libs.txt
        $ deactivate
        $ rm -rf ~/path/to/venv
        $ ... install new Python/remove old Python ...
        $ python3 -mvenv ~/path/to/venv
        $ pip install -r installed_libs.txt # Optionally add --upgrade to install latest, not fixed versions





        share|improve this answer















        Bad news: You're using venv, and venv virtual environments are not completely standalone. Even when created with --copies, all it copies is the python executable itself, not the standard libraries, not even (if your install creates a shared libpython rather than a static one) libpython; it relies on the system copy. The virtual environment will break if the Python install it was based on goes away. How it breaks will differ based on how it was created. For example, if you created it with:



        python3 -mvenv path/to/venv


        when python3 meant Python 3.7, then replaced python3 with Python 3.8, then you can fix up the virtual env for the new version with:



        python3 -mvenv --upgrade path/to/venv


        but your installed third party packages will be (effectively) gone (they'll be in path/to/venv/lib/python3.7, but Python 3.8 will only be looking in path/to/venv/lib/python3.8), so you'll have to reinstall them.



        If you created the virtual environment with:



        python3.7 -mvenv path/to/venv


        then it's completely broken (at least as documented), the --upgrade switch is only documented to work for upgrading when Python was upgraded in place; since the new Python would not be named python3.7, you can't upgrade in place. That said, --upgrade really only works well when upgrading micro versions (from 3.7.1 to 3.7.2 or the like), due to aforementioned per-minor version lib/pythonX.Y directories, so either way, you're best off just creating a new virtual environment from scratch.



        To be clear, the third party virtualenv package does not have this limitation if and only if the system Python installation statically linked libpython. Oddly, while the --always-copy flag will make it copy the main binary and the standard library modules, it doesn't cause libpython itself (the interpreter core) to be copied, so if the main binary depends on a system copy of libpython.so, then removing the system copy breaks the virtual environment. If you did use --always-copy and your python executable statically linked libpython.a (ldd /path/to/python3 should show no libpython dependency), then yes, virtualenv makes much more heavyweight (in local tests on 3.6, forcing copies via the appropriate switch, freshly created venv environments were ~11 MB, while virtualenv environments were ~48 MB; sadly, my python dynamically links libpython.so, so it still wouldn't work) virtual environments that should survive the removal of the system installed copy of Python.



        In any event, it's probably best to leave your Python 3.7 install in place, and just upgrade to 3.8 without removing 3.7 (are you really hard up for a few dozen MB of disk space?). Even if you replace python3 with the new 3.8 install, python3.7, libpython3.7m.so.1.0 or the like and the rest of the 3.7 standard library will continue to exist for the virtual environment to depend on; at worst you might need to manually change the symlink in the virtual environment to point to /path/to/python3.7 rather than /path/to/python3 to keep using the old version (including all your installed third party packages).



        An alternative to trying to keep the old virtual environment working is to just back up the installed state of that virtual environment, delete it, install the new Python, create a fresh virtual environment, and then use the backed up state to reinstall all your packages in the upgraded virtual env. An example might be:



        $ source ~/path/to/venv/bin/activate
        $ pip freeze > installed_libs.txt
        $ deactivate
        $ rm -rf ~/path/to/venv
        $ ... install new Python/remove old Python ...
        $ python3 -mvenv ~/path/to/venv
        $ pip install -r installed_libs.txt # Optionally add --upgrade to install latest, not fixed versions






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago

























        answered 2 days ago









        ShadowRangerShadowRanger

        61.9k55897




        61.9k55897























            1














            A virtualenv includes a copy of the python binary itself, so nothing should happen. See a more detailed explanation here




            virtualenv solves this problem by creating a completely isolated virtual environment for each of your programs. An environment is simply a directory that contains a complete copy of everything needed to run a Python program, including a copy of the python binary itself, a copy of the entire Python standard library, a copy of the pip installer, and (crucially) a copy of the site-packages directory mentioned above. When you install a package from PyPI using the copy of pip that's created by the virtualenv tool, it will install the package into the site-packages directory inside the virtualenv directory. You can then use it in your program just as before.




            Edit (accounting for venv vs virtualenv): According to the venv-documentation, it can either copy or symlink the binary:




            The venv module provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories. Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.







            share|improve this answer




















            • 3





              It should be noted for anyone reading this that while venv and virtualenv are similar, they are not the same package.

              – Joshua Schlichting
              2 days ago











            • Good point, edited the answer accordingly

              – dorvak
              2 days ago











            • This answer says a completely different thing than the other answers to this question, namely that it does not break when updating the system python, because it can copy it

              – Ferrybig
              2 days ago











            • @Ferrybig: That's because virtualenv (third party package) and venv (built-in part of Python standard library) behave differently. This answer was originally answered from the perspective of virtualenv (they missed the OP saying they used venv). As it happens, virtualenv still isn't guaranteed to work if the system Python goes away since libpython.so isn't copied (which seems like a bug in virtualenv, given its guarantees about standalone behavior), but it has a chance to work, where venv definitely won't.

              – ShadowRanger
              2 days ago















            1














            A virtualenv includes a copy of the python binary itself, so nothing should happen. See a more detailed explanation here




            virtualenv solves this problem by creating a completely isolated virtual environment for each of your programs. An environment is simply a directory that contains a complete copy of everything needed to run a Python program, including a copy of the python binary itself, a copy of the entire Python standard library, a copy of the pip installer, and (crucially) a copy of the site-packages directory mentioned above. When you install a package from PyPI using the copy of pip that's created by the virtualenv tool, it will install the package into the site-packages directory inside the virtualenv directory. You can then use it in your program just as before.




            Edit (accounting for venv vs virtualenv): According to the venv-documentation, it can either copy or symlink the binary:




            The venv module provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories. Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.







            share|improve this answer




















            • 3





              It should be noted for anyone reading this that while venv and virtualenv are similar, they are not the same package.

              – Joshua Schlichting
              2 days ago











            • Good point, edited the answer accordingly

              – dorvak
              2 days ago











            • This answer says a completely different thing than the other answers to this question, namely that it does not break when updating the system python, because it can copy it

              – Ferrybig
              2 days ago











            • @Ferrybig: That's because virtualenv (third party package) and venv (built-in part of Python standard library) behave differently. This answer was originally answered from the perspective of virtualenv (they missed the OP saying they used venv). As it happens, virtualenv still isn't guaranteed to work if the system Python goes away since libpython.so isn't copied (which seems like a bug in virtualenv, given its guarantees about standalone behavior), but it has a chance to work, where venv definitely won't.

              – ShadowRanger
              2 days ago













            1












            1








            1







            A virtualenv includes a copy of the python binary itself, so nothing should happen. See a more detailed explanation here




            virtualenv solves this problem by creating a completely isolated virtual environment for each of your programs. An environment is simply a directory that contains a complete copy of everything needed to run a Python program, including a copy of the python binary itself, a copy of the entire Python standard library, a copy of the pip installer, and (crucially) a copy of the site-packages directory mentioned above. When you install a package from PyPI using the copy of pip that's created by the virtualenv tool, it will install the package into the site-packages directory inside the virtualenv directory. You can then use it in your program just as before.




            Edit (accounting for venv vs virtualenv): According to the venv-documentation, it can either copy or symlink the binary:




            The venv module provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories. Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.







            share|improve this answer















            A virtualenv includes a copy of the python binary itself, so nothing should happen. See a more detailed explanation here




            virtualenv solves this problem by creating a completely isolated virtual environment for each of your programs. An environment is simply a directory that contains a complete copy of everything needed to run a Python program, including a copy of the python binary itself, a copy of the entire Python standard library, a copy of the pip installer, and (crucially) a copy of the site-packages directory mentioned above. When you install a package from PyPI using the copy of pip that's created by the virtualenv tool, it will install the package into the site-packages directory inside the virtualenv directory. You can then use it in your program just as before.




            Edit (accounting for venv vs virtualenv): According to the venv-documentation, it can either copy or symlink the binary:




            The venv module provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories. Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 days ago

























            answered 2 days ago









            dorvakdorvak

            4,38422438




            4,38422438







            • 3





              It should be noted for anyone reading this that while venv and virtualenv are similar, they are not the same package.

              – Joshua Schlichting
              2 days ago











            • Good point, edited the answer accordingly

              – dorvak
              2 days ago











            • This answer says a completely different thing than the other answers to this question, namely that it does not break when updating the system python, because it can copy it

              – Ferrybig
              2 days ago











            • @Ferrybig: That's because virtualenv (third party package) and venv (built-in part of Python standard library) behave differently. This answer was originally answered from the perspective of virtualenv (they missed the OP saying they used venv). As it happens, virtualenv still isn't guaranteed to work if the system Python goes away since libpython.so isn't copied (which seems like a bug in virtualenv, given its guarantees about standalone behavior), but it has a chance to work, where venv definitely won't.

              – ShadowRanger
              2 days ago












            • 3





              It should be noted for anyone reading this that while venv and virtualenv are similar, they are not the same package.

              – Joshua Schlichting
              2 days ago











            • Good point, edited the answer accordingly

              – dorvak
              2 days ago











            • This answer says a completely different thing than the other answers to this question, namely that it does not break when updating the system python, because it can copy it

              – Ferrybig
              2 days ago











            • @Ferrybig: That's because virtualenv (third party package) and venv (built-in part of Python standard library) behave differently. This answer was originally answered from the perspective of virtualenv (they missed the OP saying they used venv). As it happens, virtualenv still isn't guaranteed to work if the system Python goes away since libpython.so isn't copied (which seems like a bug in virtualenv, given its guarantees about standalone behavior), but it has a chance to work, where venv definitely won't.

              – ShadowRanger
              2 days ago







            3




            3





            It should be noted for anyone reading this that while venv and virtualenv are similar, they are not the same package.

            – Joshua Schlichting
            2 days ago





            It should be noted for anyone reading this that while venv and virtualenv are similar, they are not the same package.

            – Joshua Schlichting
            2 days ago













            Good point, edited the answer accordingly

            – dorvak
            2 days ago





            Good point, edited the answer accordingly

            – dorvak
            2 days ago













            This answer says a completely different thing than the other answers to this question, namely that it does not break when updating the system python, because it can copy it

            – Ferrybig
            2 days ago





            This answer says a completely different thing than the other answers to this question, namely that it does not break when updating the system python, because it can copy it

            – Ferrybig
            2 days ago













            @Ferrybig: That's because virtualenv (third party package) and venv (built-in part of Python standard library) behave differently. This answer was originally answered from the perspective of virtualenv (they missed the OP saying they used venv). As it happens, virtualenv still isn't guaranteed to work if the system Python goes away since libpython.so isn't copied (which seems like a bug in virtualenv, given its guarantees about standalone behavior), but it has a chance to work, where venv definitely won't.

            – ShadowRanger
            2 days ago





            @Ferrybig: That's because virtualenv (third party package) and venv (built-in part of Python standard library) behave differently. This answer was originally answered from the perspective of virtualenv (they missed the OP saying they used venv). As it happens, virtualenv still isn't guaranteed to work if the system Python goes away since libpython.so isn't copied (which seems like a bug in virtualenv, given its guarantees about standalone behavior), but it has a chance to work, where venv definitely won't.

            – ShadowRanger
            2 days ago

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55025873%2fconsequences-for-virtual-env-when-systems-python-is-removed-and-or-updated%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme