virtualenv python broke after upgrading ubuntu 15.10 to 16.04

后端 未结 5 701
渐次进展
渐次进展 2021-02-12 15:41

I had python 3.4 in my virtualenv, but after upgrading ubuntu to 16.04 python upgraded to 3.5 so python in virtualenv crashes with these errors:

Could not find p         


        
相关标签:
5条回答
  • 2021-02-12 16:23

    I fixed this by installing the minimum working python3.4 so that my virtualenv worked well enough to get the list of packages, then made a new one with python3.5... as follows:

    Get python3.4 minimal packages:

    wget http://launchpadlibrarian.net/221250032/python3.4-minimal_3.4.3-1ubuntu1~14.04.3_amd64.deb
    wget http://launchpadlibrarian.net/221250033/libpython3.4-minimal_3.4.3-1ubuntu1~14.04.3_amd64.deb
    sudo dpkg -i --force-breaks libpython3.4-minimal_3.4.3-1ubuntu1~14.04.3_amd64.deb
    sudo dpkg -i python3.4-minimal_3.4.3-1ubuntu1~14.04.3_amd64.deb
    

    My virtualenv is here: ~/virtualenv/example

    Get the list of packages in your virtualenv (which should now work well enough for this, but might not do other things properly):

    source ~/virtualenv/example/bin/activate
    pip freeze > /tmp/requirements.txt
    deactivate 
    

    Get rid of python3.4, to return to Ubuntu 16.04's preferred state:

    sudo dpkg --purge python3.4-minimal
    sudo dpkg --force-depends --purge libpython3.4-minimal
    

    Make a new virtualenv with the right packages:

    virtualenv -p python3.5 example
    source ~/virtualenv/example/bin/activate
    pip install -r /tmp/requirements.txt
    

    That should now work, with all your old packages but in python3.5. Should...

    See also Upgrade python in a virtualenv

    0 讨论(0)
  • 2021-02-12 16:29

    I experienced the same issue and I managed to "fix" is by recreating the virtualenv and reinstalling the required packages using pip.

    Create a new virtualenv:

    virtualenv <new-virtualenv>
    

    Activate it:

    source <new-virtualenv>/bin/activate
    

    Install the packages:

    pip install <required-packages>
    

    And I was good to go again!

    You can keep the old virtualenv by just renaming the folder:

    mv <old-virtualenv> <old-virtualenv>-backup
    
    0 讨论(0)
  • 2021-02-12 16:31

    I had the same problem today and that is how I have solved it:

    Problem: Firstly, as I understand, the problem occurs because after upgrading to Ubuntu 16.04 the previous version of Python also upgrades. As a result symbolic links inside any Python3 environment are not working anymore.

    Solution 1: As it was written above the straightforward solution is to remove all the Python3 environments and create them again. I don't like it because it is second time I do it after upgrading Ubuntu. Also probably I need to use multiple Python 3 versions in the future projects.

    Solution 2: That is what I have tried today and it is working fine. Instead of using virtualenv + virtualenvwrapper I decided to try combination of pyenv + pyenv-virtualenv.

    The main difference between two approaches is:

    Pyenv actually copies an entire Python installation every time you create a new pyenv version. In contrast, virtualenv makes use of symbolic links to decrease the size of the virtualenv’s.

    Howto:

    1. Install pyenv as described here together with required versions of Python 2 and 3.
    2. Have a look here on how you can work with virtualenv using pyenv.
    3. Create new environment, install all the dependencies with pip and hopefully forget about the problem of broken symlinks during next Ubuntu upgrade.
    0 讨论(0)
  • 2021-02-12 16:32

    I fixed it by creating a new virtualenv and copying the python executable into the old broken virtualenv.

    0 讨论(0)
  • 2021-02-12 16:36

    I have same issue and i solved recreating the whole virtualenv

    PS: Sorry for my bad English.

    0 讨论(0)
提交回复
热议问题