简体   繁体   English

如何在 anaconda 提示中激活 virtualenv 虚拟环境?

[英]How can I activate a virtualenv virtual environment in the anaconda prompt?

I am fairly new to using virtual environments for python projects but I have spent many hours trying to resolve this issue I've been having through various posts on this site and on others and have come up short.我对在 python 项目中使用虚拟环境还很陌生,但我花了很多时间试图解决这个问题,我一直在通过本网站和其他网站上的各种帖子解决这个问题,但结果不尽如人意。 I have even resorted to uninstalling all python distributions and reinstalling with no luck.我什至诉诸于卸载所有 python 发行版并重新安装,但没有运气。

I have the anaconda distribution of python installed on Windows 10. I have the problem that after I create a virtual environment, called venv, in a project folder I am unable to then activate this virtual environment using the anaconda prompt to install packages through pip.我在 Windows 10 上安装了 python 的 anaconda 发行版。我遇到的问题是,在项目文件夹中创建名为 venv 的虚拟环境后,我无法使用 anaconda 提示激活此虚拟环境以通过 pip 安装软件包。 What I have done so far is as follows:到目前为止,我所做的如下:

(base) C:\Users\[User]\Documents\GitHub\[project_folder]> virtualenv venv

This then successfully creates a virtual environment folder in my project folder called venv .然后在我的项目文件夹中成功创建了一个名为venv的虚拟环境文件夹。 Working in this directory I navigate to:在这个目录中工作,我导航到:

(base) venv> cd Scripts
(base) venv\Scripts> activate 

There are a number of activate files to choose from and neither turns the environment from base to env as expected.有许多activate文件可供选择,但都没有按预期将环境从baseenv

The reason I am using anaconda prompt as opposed to the standard command prompt or Windows PowerShell is because when I'm using the pip install <package> anywhere but in the anaconda prompt I get an error message that reads:我使用 anaconda 提示符而不是标准命令提示符或 Windows PowerShell 的原因是因为当我在任何地方使用pip install <package>但在 anaconda 提示符中时,我收到一条错误消息,内容如下:

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

I'm not sure what this means and have tried to do some googling to solve this issue but to no avail.我不确定这意味着什么,并尝试使用谷歌搜索来解决此问题,但无济于事。 Note I do not have this issue when working on python projects on my MacBook and I can easily enter virtual environments and install the packages there with no issues.注意我在我的 MacBook 上处理 python 项目时没有这个问题,我可以轻松进入虚拟环境并在那里安装包,没有问题。 I'm relatively new to Windows so perhaps I'm missing something here...?我对 Windows 比较陌生,所以也许我在这里遗漏了一些东西......?

An interesting observation is that I can enter any virtual environment I've created through Windows PowerShell but I encounter the pip problem described above when trying to install packages into this environment.一个有趣的发现是,我可以进入我通过 Windows PowerShell 创建的任何虚拟环境,但是在尝试将包安装到该环境中时遇到了上述 pip 问题。

I'm desperate for some help resolving this issue as it's greatly hindering the work on all my projects, and unfortunately I cannot just use my MacBook to code either.我迫切需要一些帮助来解决这个问题,因为它极大地阻碍了我所有项目的工作,不幸的是我也不能只使用我的 MacBook 来编码。

use those command for python virtualenv将这些命令用于 python virtualenv

For activate 
WINDOWS: activate nameofvenv
LINUX, macOS: source activate nameofvenv

For deactivate 
WINDOWS: deactivate
macOS, LINUX: source deactivate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM