【发布时间】:2023-12-20 13:24:01
【问题描述】:
我在 Windows 中使用 Python 和 Django 的经验有限,现在我正在尝试了解如何将我的代码部署到 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。所以我假设source activate 不能通过 Paramiko 的 SSH 工作。
- 为什么?
- 我该如何应对?
- 我能否检查是否以更直接(和可靠)的方式启用了 venv?
【问题讨论】:
标签: python ubuntu ssh virtualenv paramiko