强制pipenv创造一个新的virtualenv

时间:2018-02-08 07:37:23

标签: python pip virtualenv pipenv

我通过下载virtualenv安装了pip,并创建了一个bootstrap virtualenv,如this answer中所述。

现在我想尝试pipenv,所以我使用我的bootstrap virtualenv来创建一个新的virtualenv,然后运行pip install pipenv。现在我可以使用pipenv,但它发现它已经在virtualenv中运行,并且没有创建新的。

如何让pipenv创建一个新的virtualenv,这样我就可以为每个项目提供单独的virtualenv?我试过了pipenv install -h,但没有一个选项看起来很有希望。

3 个答案:

答案 0 :(得分:3)

current documentation听起来像你可以设置环境变量{ "size": 0, "aggs": { "HEATMAP": { "date_histogram": { "field": "created", "interval": "day" }, "aggs": { "BEHAVIOUR_CHANGE": { "terms": { "field": "labels", "include": "behavior-change" } }, "FIRST_OCCURRENCE": { "terms": { "field": "labels", "include": "first-occurrence" } } } } } } ,以避免重用已经激活的virtualenv:

{
  "size": 0,
  "aggs": {
    "HEATMAP": {
      "date_histogram": {
        "field": "created",
        "interval": "day"
      },
      "aggs": {
        "BEHAVIOUR_CHANGE": {
          "filter": {
            "regexp": {
              "labels": "behavior-change"
            }
          }
        },
        "FIRST_OCCURRENCE": {
          "filter": {
            "regexp": {
              "labels": "first-occurrence"
            }
          }
        }
      }
    }
  }
}

我必须承认,我还没试过这个。

答案 1 :(得分:1)

如果您在新项目目录中,这些命令会使用pipenv创建一个新的virtualenv:

使用python 2创建一个新的virtualenv:

pipenv --two

使用python 3创建一个新的virtualenv:

pipenv --three

使用任意python版本创建一个新的virtualenv:

pipenv --python 3.6.4

答案 2 :(得分:0)

对于这种情况,pipenv似乎变得越来越聪明。这对我有用。首先,我在virtualenv的installation documentation之后安装了一个引导环境,以从源代码本地使用它。这样,我无需接触系统Python,就可以在引导环境中安装pipenv:

     test/foo/__init__.py", line 2, in <module>

     from test.foo.a import begin

     File "/test/foo/a.py", line 17, in <module>

     from . import foo

     ImportError: cannot import name api

然后我创建了一个新的项目文件夹,并使用pipenv安装了numpy:

$ curl --location --output virtualenv.tar.gz https://github.com/pypa/virtualenv/tarball/16.1.0
$ tar -xzf virtualenv.tar.gz
$ python pypa-virtualenv-4ad2742/src/virtualenv.py vbootstrap
$ rm -r virtualenv.tar.gz pypa-virtualenv-4ad2742/
$ vbootstrap/bin/pip install pipenv

为了易于使用,我创建了一个符号链接:

$ mkdir my_project
$ cd my_project
$ ../vbootstrap/bin/pipenv install numpy
Creating a virtualenv for this project...
Pipfile: /home/vagrant/my_project/Pipfile
Using /home/vagrant/vbootstrap/bin/python (2.7.15rc1) to create virtualenv...
✔ Complete 
Already using interpreter /home/vagrant/vbootstrap/bin/python
Using real prefix '/usr'
New python executable in /home/vagrant/.local/share/virtualenvs/my_project-KmT425B_/bin/python
Installing setuptools, pip, wheel...
done.
Virtualenv location: /home/vagrant/.local/share/virtualenvs/my_project-KmT425B_
Creating a Pipfile for this project...
Installing numpy...
Adding numpy to Pipfile's [packages]...
✔ Installation Succeeded 
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
✔ Success! 
Updated Pipfile.lock (57a39c)!
Installing dependencies from Pipfile.lock (57a39c)...
     ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.