问题:virtualenv的问题-无法激活

我在项目周围创建了一个virtualenv,但是当我尝试激活它时却无法。它可能只是语法或文件夹位置,但是我现在很困惑。

您可以在下面看到,我创建了virtualenv并将其称为venv。一切看起来不错,然后我尝试通过运行来激活它source venv/bin/activate

我在想这可能与我的系统路径有关,但不确定要指向什么(我确实知道如何编辑路径)。我在python 7 / Windows OS上,虚拟环境2.2.x

处理virtualenv的依赖项
已完成virtualenv的处理依赖性

c:\ testdjangoproj \ mysite> virtualenv --no-site-packages venv
--no-site-packages标志已弃用;现在是默认行为。
使用真实的前缀'C:\\ Program Files(x86)\\ Python'
venv \ Scripts \ python.exe中的新python可执行文件
venv \ Lib \ distutils \ distutils.cfg文件存在不同的内容;不过度
ting
安装setuptools ........完成。
安装pip .........完成。

c:\ testdjangoproj \ mysite>源venv / bin / activate
无法将“源”识别为内部或外部命令,
可操作的程序或批处理文件。

c:\ testdjangoproj \ mysite>源venv / bin / activate
无法将“源”识别为内部或外部命令,
可操作的程序或批处理文件。

c:\ testdjangoproj \ mysite>来源mysite / bin / activate
无法将“源”识别为内部或外部命令,
可操作的程序或批处理文件。

c:\ testdjangoproj \ mysite>

I created a virtualenv around my project, but when I try to activate it I cannot. It might just be syntax or folder location, but I am stumped right now.

You can see below, I create the virtualenv and call it venv. Everything looks good, then I try to activate it by running source venv/bin/activate

I’m thinking it might just have to do with my system path, but not sure what to point it to (I do know how to edit the path). I’m on python 7 / windows os, virtual env 2.2.x

Processing dependencies for virtualenv
Finished processing dependencies for virtualenv

c:\testdjangoproj\mysite>virtualenv --no-site-packages venv
The --no-site-packages flag is deprecated; it is now the default behavior.
Using real prefix 'C:\\Program Files (x86)\\Python'
New python executable in venv\Scripts\python.exe
File venv\Lib\distutils\distutils.cfg exists with different content; not overwri
ting
Installing setuptools.................done.
Installing pip...................done.

c:\testdjangoproj\mysite>source venv/bin/activate
'source' is not recognized as an internal or external command,
operable program or batch file.

c:\testdjangoproj\mysite>source venv/bin/activate
'source' is not recognized as an internal or external command,
operable program or batch file.

c:\testdjangoproj\mysite>source mysite/bin/activate
'source' is not recognized as an internal or external command,
operable program or batch file.

c:\testdjangoproj\mysite>

回答 0

source 是为在Linux(或任何Posix,但不包括Windows)上运行的用户设计的shell命令。

在Windows上,virtualenv会创建一个批处理文件,因此您应该venv\Scripts\activate改为运行它(根据Activate 脚本上的 virtualenv 文档)。

编辑: 这里的Windows技巧不是指定BAT扩展名:

PS C:\ DEV \ aProject \ env \ Scripts> ..activate
(env)PS C:\ DEV \ aProject \ env \ Scripts>

source is a shell command designed for users running on Linux (or any Posix, but whatever, not Windows).

On Windows, virtualenv creates a batch file, so you should run venv\Scripts\activate instead (per the virtualenv documentation on the activate script).

Edit: The trick here for Windows is not specifying the BAT extension:

PS C:\DEV\aProject\env\Scripts> & .\activate
(env) PS C:\DEV\aProject\env\Scripts>


回答 1

我的Windows 10机器中也遇到了同样的问题。我尝试过的步骤是:

转到andconda终端步骤1

pip3 install -U pip virtualenv

第2步

virtualenv --system-site-packages -p python ./venv

要么

virtualenv --system-site-packages -p python3 ./venv

第三步

.\venv\Scripts\activate

您可以通过键入Python中的蜘蛛工具来检查它 import tensorflow as tf

I was also facing the same issue in my Windows 10 machine. What steps i tried were:

Go to andconda terminal Step 1

pip3 install -U pip virtualenv

Step 2

virtualenv --system-site-packages -p python ./venv

or

virtualenv --system-site-packages -p python3 ./venv

Step 3

.\venv\Scripts\activate

You can check it via spider tool in anaconda by typing import tensorflow as tf


回答 2

我有同样的问题。我正在使用Python 2,Windows 10和Git Bash。事实证明,您需要使用Git Bash:

 source venv/Scripts/activate

I had the same problem. I was using Python 2, Windows 10 and Git Bash. Turns out in Git Bash you need to use:

 source venv/Scripts/activate

回答 3

  1. 要进行激活,您可以通过转到venv您的virtualenv目录cd venv

  2. 然后在Windows上,键入dir(在UNIX上,键入ls)。您将获得5个文件夹includeLibScriptstcl和60

  3. 现在键入.\Scripts\activate以激活您的virtualenv venv

您的提示将更改以指示您现在正在虚拟环境中操作。它看起来像这样(venv)user@host:~/venv$

并且您venv现在被激活了。

  1. For activation you can go to the venv your virtualenv directory by cd venv.

  2. Then on Windows, type dir (on unix, type ls). You will get 5 folders include, Lib, Scripts, tcl and 60

  3. Now type .\Scripts\activate to activate your virtualenv venv.

Your prompt will change to indicate that you are now operating within the virtual environment. It will look something like this (venv)user@host:~/venv$.

And your venv is activated now.


回答 4

对于Windows,在没有引号的终端中键入“ C:\ Users \ Sid \ venv \ FirstProject \ Scripts \ activate”。只需提供您的Scripts文件夹在项目中的位置。因此,该命令将为location_of_the_Scripts_Folder \ activate。在此处输入图片说明

For windows, type “C:\Users\Sid\venv\FirstProject\Scripts\activate” in the terminal without quotes. Simply give the location of your Scripts folder in your project. So, the command will be location_of_the_Scripts_Folder\activate.enter image description here


回答 5

确保venv在那,并按照以下命令操作。它适用于Windows 10。

转到您希望虚拟环境驻留的路径:

> cd <my_venv_path>

创建名为“ env”的虚拟环境:

> python -m venv env 

将路径添加到git ignore文件(可选):

> echo env/ >> .gitignore

激活虚拟环境:

> .\env\Scripts\activate

Ensure venv is there and just follow the commands below. It works in Windows 10.

Go to the path where you want your virtual enviroments to reside:

> cd <my_venv_path>

Create the virtual environment named “env”:

> python -m venv env 

Add the path to the git ignore file (optional):

> echo env/ >> .gitignore

Activate the virtual env:

> .\env\Scripts\activate

回答 6

virtualenv在使用git bash的Windows上玩得很开心,我通常最终会明确指定python二进制文件。

如果我的环境在,.env我会通过./.env/Scripts/python.exe …或在shebang行中调用python#!./.env/Scripts/python.exe ;

两者都假设您的工作目录包含您的virtualenv(.env)。

I have a hell of a time using virtualenv on windows with git bash, I usually end up specifying the python binary explicitly.

If my environment is in say .env I’ll call python via ./.env/Scripts/python.exe …, or in a shebang line #!./.env/Scripts/python.exe;

Both assuming your working directory contains your virtualenv (.env).


回答 7

您可以在cygwin终端上运行source命令

You can run the source command on cygwin terminal


回答 8

如果你看到5个文件夹(IncludeLibScriptstclpip-selfcheck使用后)virtualenv yourenvname命令,更改目录到Scripts文件夹在CMD本身并简单地用“ 激活 ”命令。

If you see the 5 folders (Include,Lib,Scripts,tcl,pip-selfcheck) after using the virtualenv yourenvname command, change directory to Scripts folder in the cmd itself and simply use “activate” command.


回答 9

使用任何gitbash控制台打开文件夹。例如,使用visualCode和Gitbash控制台程序:1)为Windows安装Gitbash

2)使用VisualCode IDE,右键单击在终端控制台中打开的项目 选项

3)在Visualcode的窗口控制台上,查找Select-> 默认外壳并将其更改为Gitbash

4)现在您的项目已使用bash控制台和正确的路径打开,放入 源代码./Scripts/activate

顺便说一句:空格=

在此处输入图片说明

open the folder with any gitbash console. for example using visualCode and Gitbash console program: 1)Install Gitbash for windows

2) using VisualCode IDE, right click over the project open in terminal console option

3) on window console in Visualcode, looking for a Select->default shell and change it for Gitbash

4)now your project is open with bash console and right path, put source ./Scripts/activate

btw : . with blank space = source

enter image description here


回答 10

提醒一下,但我在Win10 cmd上使用了错误的方式。根据python 文档,activate命令是:C:\> <venv>\Scripts\activate.bat 浏览目录时,例如cd .env/Scripts

因此,创建我使用过的静脉python -m venv --copies .env并激活.env\Scripts\activate.bat

A small reminder, but I had my slashes the wrong way on Win10 cmd. According to python documentation the activate command is: C:\> <venv>\Scripts\activate.bat When you’re browsing directories it’s e.g. cd .env/Scripts

So to create my venv I used python -m venv --copies .env and to activate .env\Scripts\activate.bat


回答 11

source命令正式用于Unix操作系统家族,您基本上不能在Windows上使用它。相反,您可以使用venv\Scripts\activate命令来激活您的虚拟环境。

制作了venv \ Scripts \ activate命令如何正常工作的屏幕截图

source command is officially for Unix operating systems family and you can’t use it on windows basically. instead, you can use venv\Scripts\activate command to activate your virtual environment.

Made a Screenshot of how venv\Scripts\activate command works correctly


回答 12

如果您使用的是Windows,请使用命令“ venv \ Scripts \ activate”(无单词source)激活虚拟环境。如果您使用的是PowerShell,则可能需要大写激活。

If you’re using Windows, use the command “venv\Scripts\activate” (without the word source) to activate the virtual environment. If you’re using PowerShell, you might need to capitalize Activate.


回答 13

如果您使用的是Windows操作系统,则在Gitbash终端中使用以下命令$ source venv / Scripts / activate。这将帮助您进入虚拟环境。

If you are using windows OS then in Gitbash terminal use the following command $source venv/Scripts/activate. This will help you to enter the virtual environment.


回答 14

  1. 使用VS代码编辑器打开项目。
  2. 将vs代码终端中的默认shell更改为git bash。

  3. 现在,您的项目已使用bash控制台打开且路径正确,将“ source venv \ Scripts \ activate”放入Windows

  1. Open your project using VS code editor .
  2. Change the default shell in vs code terminal to git bash.

  3. now your project is open with bash console and right path, put “source venv\Scripts\activate” in Windows


回答 15

导航到您的virtualenv文件夹,例如,..\project1_env> 然后输入

source scripts/activate

例如 ..\project1_env>source scripts/activate

Navigate to your virtualenv folder eg ..\project1_env> Then type

source scripts/activate

eg ..\project1_env>source scripts/activate


回答 16

如果像我这样的初学者遵循了多个Python教程,则现在可能具有多个Python版本和/或pip / virtualenv / pipenv的多个版本…

在这种情况下,列出的答案虽然很正确,但可能无济于事。

我要在您的位置尝试的第一件事是卸载并重新安装Python,然后从那里开始。

If some beginner, like me, has followed multiple Python tutorials now possible has multiple Python versions and/or multiple versions of pip/virtualenv/pipenv…

In that case, answers listed, while many correct, might not help.

The first thing I would try in your place is uninstall and reinstall Python and go from there.


回答 17

在Windows平台上,

您应该将此命令与在安装虚拟环境的位置指定的路径一起使用。

$ .\env\Scripts\activate 

这样,您应该能够在Windows上激活它。

In Windows platform,

you should use this command with path specified where you have installed a virtual environment.

$ .\env\Scripts\activate 

By this, You should be able to activate this on windows.


回答 18

  1. 以管理员身份打开Powershell
  2. 输入“ Set-ExecutionPolicy RemoteSigned -Force
  3. 运行“ gpedit.msc”,然后转到>管理模板> Windows组件> Windows Powershell
  4. 查找“激活脚本执行”并将其设置为“已激活”
  5. 将执行指令设置为“全部允许”
  6. 应用
  7. 刷新您的环境
  1. Open your powershell as admin
  2. Enter “Set-ExecutionPolicy RemoteSigned -Force
  3. Run “gpedit.msc” and go to >Administrative Templates>Windows Components>Windows Powershell
  4. Look for “Activate scripts execution” and set it on “Activated”
  5. Set execution directive to “Allow All”
  6. Apply
  7. Refresh your env

回答 19

如果您在Windows上使用Anaconda / miniconda,请在命令提示符下使用

conda activate <your-environmentname>

例如,peopleanalytics是我的虚拟环境的名称-说

conda activate peopleanalytics

Incase you are using Anaconda / miniconda on windows – in your command prompt use

conda activate <your-environmentname>

e.g. peopleanalytics is name of my virtual environment – Is say

conda activate peopleanalytics

回答 20

如果您仅在Windows 10中已经CD了项目类型

Scripts/activate

这对我行得通:)

if you already cd your project type only in windows 10

Scripts/activate

That works for me:)


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。