hellopython@ubuntu:~$ which python3
/usr/bin/python3
hellopython@ubuntu:~$ mkvirtualenv -p /usr/bin/python3 dm
mkvirtualenv: command not found
參考:https://blog.csdn.net/liu_xzhen/article/details/79293373#commentsedit
執行命令
sudo apt-get install python-virtualenv
sudo easy_install virtualenvwrapper
其中easy_install 出問題了,參考:https://blog.csdn.net/weixin_43256057/article/details/102984840
hellopython@ubuntu:~$ mkdir $HOME/.virtualenvs
hellopython@ubuntu:~$ export WORKON_HOME=$HOME/.virtualenvs
hellopython@ubuntu:~$ source /usr/local/bin/virtualenvwrapper.sh
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/get_env_details
hellopython@ubuntu:~$ ls -a
. .config .ICEauthority .pam_environment setuptools-33.1.1.zip Templates
.. Desktop .java Pictures snap Videos
.bash_history Documents java_error_in_PYCHARM_20211.log .profile .ssh .virtualenvs
.bash_logout Downloads .local Public sublime_text_3 .wget-hsts
.bashrc examples.desktop .mozilla .PyCharm2019.2 sublime_text_3_build_3114_x64.tar.bz2 .xinputrc
.cache .gnupg Music PycharmProjects .sudo_as_admin_successful
hellopython@ubuntu:~$ source ~/.bashrc
hellopython@ubuntu:~$ mkvirtualenv -p /usr/bin/python3 dm
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/hellopython/.virtualenvs/dm/bin/python3
Also creating executable in /home/hellopython/.virtualenvs/dm/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/dm/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/dm/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/dm/bin/preactivate
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/dm/bin/postactivate
virtualenvwrapper.user_scripts creating /home/hellopython/.virtualenvs/dm/bin/get_env_details
(dm) hellopython@ubuntu:~$
就這樣成功地創建虛擬環境並進去了。
補充:source xx.sh 是無需權限直接讀取xx.sh腳本並運行裏面的命令的意思。