简体   繁体   中英

Virtualenv did not work on docker ubuntu18.04: Problem on Python2 -> Python3?

My environment on docker was built based on ubuntu 18.04. The OS is in a transitional period shifting Python2 to Python3.

Where I need to use virtualenv command. However, below error occurred. How should I solve?

The command was called from a toolchain.

Therefore, I want to solve this problem with the exception of changing command.

$virtualenv --python=python3 venv
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/hostcwd/venv/bin/python' -> '/home/user/hostcwd/venv/bin/python3'

Added @ 2/14 22:32

in venv dir, directories bin, lib. a file pyvenv.cfg.

ls -la venv/bin/python
lrwxrwxrwx 1 user user 16 Feb 14 09:06 venv/bin/python -> /usr/bin/python3

I'm not sure I understand your full problem. I just did the following:

$ docker pull ubuntu:bionic
$ docker run -it --rm ubuntu:bionic

Now in the container

$ apt update
$ apt install python3-pip
$ pip install virtualenv
$ virtualenv -p python3 myenv
$ source myenv/bin/activate
(myenv) $ python

Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

So it setup the virutalenv for python properly. You can list those commands in a Dockerfile to replicate what I did pretty easily.

When I call ls -l $(which python3) before I source the environment I get

lrwxrwxrwx 1 root root 9 Oct 25  2018 /usr/bin/python3 -> python3.6

So, perhaps, your virtualenv was installed with pip (for python2) and that is somehow causing an issue. I'd try purging virtualenv and installing it via python3. Containers are meant to be ephemeral and easily rebuilt. If there is any other configurations you're using to build your container that might help shed light on your situation please share.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM