我尝试使用Cloud9
中的自定义跑步者使用安装在同一目录中的虚拟环境在python 3.4
下启动项目,但它不起作用。跑步者没有检测到我的依赖关系,这可能意味着它没有正确激活venv
。
// Create a custom Cloud9 runner - similar to the Sublime build system
// For more information see https://docs.c9.io/custom_runners.html
{
"cmd": [
"bash",
"--login",
"-c",
"source bin/activate && python oric.py"
],
"working_dir": "$project_path",
"info": "Your code is running at \\033[01;34m$url\\033[00m.\n\\033[01;31m"
}
对于什么是错误的任何想法?非常感谢
答案 0 :(得分:1)
为了使用在Cloud9上安装的python版本3,您需要使用python3
(和pip3
分别安装模块)。
答案 1 :(得分:1)
我通过直接设置环境变量而不是尝试获取激活脚本来让cloud9使用virtualenv。
{
"cmd": [
"/var/lib/cloud9/venv/bin/python",
"$file",
"$args"
],
"selector": "^.*\\.(python|py)$",
"env": {
"PYTHONPATH": "/var/lib/cloud9/venv/lib/python3.5/site-packages",
"VIRTUAL_ENV": "/var/lib/cloud9/venv",
"PATH": "/var/lib/cloud9/venv/bin:$PATH"
}
}
答案 2 :(得分:1)
从头到尾:
$ virtualenv -p /usr/bin/python36 vpy36
$ source vpy36/bin/activate $ pip3 install tweepy
将下面的示例代码复制并粘贴到您的.run文件中。这将允许您的venv正常执行和调试执行。
// This file overrides the built-in Python 3 runner
// For more information see http://docs.aws.amazon.com/console/cloud9/change-runner
{
"script": [
"if [ \"$debug\" == true ]; then ",
" /home/ec2-user/environment/venvpy36/bin/python -m ikp3db -ik_p=15471 -ik_cwd=$project_path \"$file\" $args",
"else",
" /home/ec2-user/environment/venvpy36/bin/python \"$file\" $args",
"fi",
"checkExitCode() {",
" if [ $1 ] && [ \"$debug\" == true ]; then ",
" /home/ec2-user/environment/venvpy36/bin/python -m ikp3db 2>&1 | grep -q 'No module' && echo '",
" To use python debugger install ikpdb by running: ",
" sudo yum update;",
" sudo yum install python36-devel;",
" sudo source /home/ec2-user/environment/venvpy36/bin activate",
" sudo pip-3.6 install ikp3db;",
" sudo deactivate",
" '",
" fi",
" return $1",
"}",
"checkExitCode $?"
],
"python_version": "/home/ec2-user/environment/venvpy36/bin/python",
"working_dir": "$project_path",
"debugport": 15471,
"$debugDefaultState": false,
"debugger": "ikpdb",
"selector": "^.*\\.(py)$",
"env": {
"PYTHONPATH": "$python_path"
},
"trackId": "/home/ec2-user/environment/venvpy36/bin/python"
}
如果您在第1步中将venv放在其他目录中,请使用自己的venv bin目录和“ / home / ec2-user / environment / venvpy36 / bin”查找并替换所有引用代码应该适合您。
选择Runner并运行文件: 选择您的跑步者(在此示例中为“ vpy36”)。然后单击“运行”,它应该可以工作。
答案 3 :(得分:0)
我在Cloud9上使用virtualenv,它对我来说很好用。 Cloud9工作区似乎预先安装了virtualenv包装器(至少,Django工作区确实如此),因此如果您使用以下命令创建virtualenv:
Red
然后,你可以这样创建你的跑步者,例如:
$ mkvirtualenv foo