【问题标题】:Virtual environment not setting properly in python using python setup.py develop使用 python setup.py develop 在 python 中未正确设置虚拟环境
【发布时间】:2015-02-21 19:55:40
【问题描述】:

我将同一个 repo 的 2 个分支作为输入。然后我签出第一个分支并执行 python setup.py develop 然后运行测试脚本。 然后我存储更改,然后检查第二个分支并执行 python setup.py develop 然后再次运行测试脚本。最后我比较结果。 在这里,我得到的结果都是一样的。我试图检查日志,但一切看起来都很好。谁能提出可能是什么问题?

    execute_git_command('git stash')
    execute_git_command('git checkout ' + branch_one)
    comment_requirements_file()
    execute_git_command('python setup.py develop') #setup_virtual_env
    branch1_script_results_list = run_the_scoring_script(branch_one)
    execute_git_command('python setup.py develop --uninstall')

    execute_git_command('git stash')
    execute_git_command('git checkout ' + branch_two)
    comment_requirements_file()
    execute_git_command('python setup.py develop') #setup_virtual_env
    branch2_script_results_list = run_the_scoring_script(branch_two)
    execute_git_command('python setup.py develop --uninstall')

    print branch1_script_results_list
    print branch2_script_results_list

def execute_git_command(git_command):
    pr = subprocess.Popen(git_command,
                          shell=True,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
    (out, error) = pr.communicate()

【问题讨论】:

    标签: python git python-2.7 subprocess


    【解决方案1】:

    python setup.py develop 没有设置虚拟环境。它就地安装包。如果python 指的是系统python,那么您的包将对系统全局可用。

    我不确定卸载选项对setup.py 的效果如何。您可以尝试pip install -e . 就地安装软件包。并pip uninstall <package_name> 卸载它。

    要在给定的 virtualenv 中运行命令,您可以使用 vex utility:

    $ vex <virtualenv_name> <command>
    

    或者要为给定的 shell 会话激活 virtualenv,请从 virtualenvwrapper package 调用 workon shell 函数:

    $ workon <virtualenv_name>
    $ <command1>
    $ <command2>
    $ deactivate
    

    你可以use tox to run the tests in different virtualenvs

    【讨论】:

      猜你喜欢
      • 2020-09-23
      • 2020-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多