我对Python和Django在Windows上有一些有限的经验,现在我正在尝试了解如何将我的代码部署到Ubuntu 16.04 LTS VPS。在阅读了各种教程和大量SE上的答案后,我已经取得了相当大的进展(对于我来说),但现在我陷入了困境。
通过Putty手动操作,我可以执行以下操作:
# check that Python 3.5 is installed
python3 --version
# install pip
sudo -kS apt-get -y install python3-pip
# upgrade pip to newest version
pip3 install --upgrade pip
# check result
pip3 --version
# install venv
sudo -kS pip3 install virtualenv virtualenvwrapper
# create venv
virtualenv ~/Env/firstsite
# make sure venv is created
ls -l ~/Env/firstsite/bin/python # /home/droplet/Env/firstsite/bin/python3.5 -> python3
# switch on venv
source ~/Env/firstsite/bin/activate # (firstsite) droplet@hostname:~$
# check that python3 is taken from venv
which python3 # /home/droplet/Env/firstsite/bin/python3
虚拟环境已经创建并启动,我可以继续安装Django。
但是当我尝试使用Paramiko在自动化模式下执行相同的操作时(我使用paramiko.SSHClient().exec_command(cmd, input_string, get_pty=False
执行命令),一切都进行得完美,直到最后一个命令:
exec_command('which python3')
返回结果为/usr/bin/python3
。因此,我假设通过Paramiko的SSH无法使用source activate
。
- 为什么?
- 我该如何应对?
- 有没有更直接(且可靠)的方式检查虚拟环境是否已启用?