It is very likely to report an error when executing the above file
在docker中安装 虚拟环境时执行
source /usr/local/bin/virtualenvwrapper.sh
报错:
/usr/local/bin/virtualenvwrapper.sh: line 230:: command not found
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could notimport the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=and that PATH isset properly.
Reason: Because there is the following code in virtualenvwrapper.sh
# Locate the global Python where virtualenvwrapper is installed.if["$VIRTUALENVWRAPPER_PYTHON"=""] then
VIRTUALENVWRAPPER_PYTHON="$(command \which python)"# 脚本会默认使用python2环境,但是virtualenvwrapper装在了python3环境中,所以会有上面的报错
Solution: Search the file path of local python3 directly
Then install the virtual environment in the same way in docker
After we run the program directly in the local virtual environment, we can pull the entire environment into docker to prevent errors. Please see:
Senior's answer:
Then start writing dockerfile
The main idea is to package our entire virtual environment all the way to the corresponding docker directory.
We move this environment package to the same virtual environment directory as docker, but we will find that pip and python in the virtual environment cannot be used, don’t worry, Need to change it. Just
change the path corresponding to these two locations to be correct! These two files are pip and activate respectively .