【问题标题】:Pipenv with Conda?Pipenv 与 Conda?
【发布时间】:2018-11-05 20:45:37
【问题描述】:

我在 win 10 中将 Anaconda 用于我的 virtualenvs。我正在使用 git-bash。我最近一直在阅读有关 pipenv 的信息并决定尝试一下。我在我的基础 conda python 上安装了 pipenv,它是 python 2.7 的一个版本,使用:

pip install pipenv

我可以轻松地创建一个 python 环境使用

conda create --name py3 python=3.6

但我试过了:

$ pipenv install --three

给了:

Warning: Python 3 was not found on your system…
You can specify specific versions of Python with:
  $ pipenv --python path\to\python
....\miniconda2\lib\site-packages\pipenv\_compat.py:86: ResourceWarning: Implicitly cleaning up <TemporaryDirectory 'c:\\users\\......\\appdata\\local\\temp\\pipenv-4_fzvq-requi
rements'>
  warnings.warn(warn_message, ResourceWarning)

这两个包可以一起用吗?

【问题讨论】:

  • 你需要在你的路径上有python3或明确声明它。
  • 好的,我也读过,但是我的 anaconda 在基本路径中有一个 python27 而不是 python3。有没有办法在那里添加python3?

标签: python anaconda git-bash pipenv


【解决方案1】:

您可以设置 Pipenv 以使用 Conda 的 Python 可执行文件和站点包目录 (ref)。

pipenv --python=$(conda run which python) --site-packages

您可以检查您是否确实在 Pipenv 中使用了您的 Conda 环境:

pipenv run python
>>> import sys
>>> sys.executable, sys.path
# <directories under your Conda environment>

通过 Conda 而不是 Pipenv 安装 NumPy,您可以看到 Pipenv 仍然会找到 NumPy。

conda install numpy
pipenv run python
>>> import numpy as np
>>> np.__file__
# <path under your Conda environment>

当你通过 Pipenv 安装 NumPy 时,它会影响 Conda 对包的安装。

pipenv install numpy
pipenv run python
>>> import numpy as np
>>> np.__file__
# <path under your Pipenv environment>

【讨论】:

  • 如何撤消pipenv --python=$(conda run which python) --site-packages? @anishpatel
【解决方案2】:

您可以在使用 python 3 初始化的 conda 环境中安装 pipenv。

$ conda create -n pipenv-test python=3
$ source activate pipenv-test
(pipenv-test)$ pipenv install --python=/home/.../miniconda3/envs/pipenv-test/bin/python
Creating a virtualenv for this project…
Using /home/.../miniconda3/envs/pipenv-test/bin/python (3.6.5) to create virtualenv…
⠋Already using interpreter /home/.../miniconda3/envs/pipenv-test/bin/python
Using base prefix '/home/.../miniconda3/envs/pipenv-test'
New python executable in /home/.../.local/share/virtualenvs/wispy-j1ojliDY/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /home/.../.local/share/virtualenvs/wispy-j1ojliDY
Creating a Pipfile for this project…
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (ca72e7)!
Installing dependencies from Pipfile.lock (ca72e7)…
  ?   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run the following:
 $ pipenv shell

这似乎对我有用,但我尚未对其进行广泛测试。另外,我的基础 conda python 是 3.6,我使用的是 Ubuntu 16.04。我很想知道这是否还会给您带来麻烦。

【讨论】:

  • 我正在 git-bash 中尝试你的命令。在 pipenv-test conda env 中,您需要在 '$ pipenv install ..miniconda\envs\pipenv-test 之前运行 pip install pipenv 吗? '
  • 我做了'conda install pip',但事实证明它是默认安装的。您可以使用“conda list”检查它是否存在。但这可能是linux和window anaconda git bash的区别。
  • 您的步骤如何显示“您可以在使用 Python 3 初始化的 conda 环境中安装 pipenv”?这似乎意味着在环境中运行类似 pip install pipenv 的东西,但您的说明假设 pipenv 在激活后已经可用。
  • 抱歉回复缓慢。 @rob3c 你是对的,我忘了在我的原始答案中包含它。事实上,我首先在 conda 环境中做了pip install pipenv
  • 将 pip 与 conda 一起使用并不是一件好事。 anaconda.com/using-pip-in-a-conda-environment
【解决方案3】:

没有'$'

pipenv install --three

【讨论】:

  • 我相信$ 是终端入口,而不是命令的一部分...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-22
  • 1970-01-01
  • 1970-01-01
  • 2021-06-17
  • 1970-01-01
  • 2023-01-26
  • 2020-03-06
相关资源
最近更新 更多