I've installed Python 3.5 using Anaconda and 2.7 using the following command:
conda create -n py27 python=2.7 anaconda
This successfully installed 2.7 as a separate environment with the Anaconda3 folder:
# original installation path for 3.5
C:\Users\username\AppData\Local\Continuum\Anaconda3
# path for 2.7 after conda create -n is run
C:\Users\username\AppData\Local\Continuum\Anaconda3\envs\py27
This works great as long as I'm using an IDE like Spyder or IPython Notebook, where I can choose which Python version. However, I have not been able to use py27 (Python 2.7) in the PowerShell. I've tried using:
activate py27
yet python command still fires up 3.5 and py27 causes this error:
py27 : The term 'py27' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1 + py27
+ ~~~~
+ CategoryInfo : ObjectNotFound: (py27:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I've tried everything I know or have read here on SO, but nothing I've tried has been able to resolve the issue. I'm not sure if this helps, but here is my PATH variable for reference:
C:\Users\username\AppData\Local\Continuum\Anaconda3;C:\Users\username\AppData\Local\Continuum\Anaconda3\Scripts;C:\Users\username\AppData\Local\Continuum\Anaconda3\Library\bin;%SystemRoot%\system32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;[stuff in between];C:\Users\username\AppData\Local\Continuum\Anaconda3\envs\p27;C:\Users\username\AppData\Local\Continuum\Anaconda3\envs\p27\Scripts\;C:\Users\username\AppData\Local\Continuum\Anaconda3\envs\p27\Library\bin
I've decided to close this question with the following solution: use Cmd.exe or use the PowerShell with Bill Stewart's Invoke-CmdScript (see comments). First, the simpler solution using the Command Prompt (Cmd.exe):
# to activate
C:\Users\me\> activate py2
# to deactivate and return to Python 3.5
C:\Users\me\> deactivate
Which activates the Python 2.7 environment I created using conda. Now, for the Powershell version. First, go this site and download the Environment.ps1 script. For me, it downloaded as text file, so I opened the file, removed the .txt extension and replaced it with .ps1. So, let's say I saved Environment.ps1 in the following directory C:\Users\user_name\AppData\Local\invoke_cmdscript. Take this path and add it to the PATH user variable within the Environment variables form. Now, the commands to type in your PowerShell window:
# dot-source my file
. Environment.ps1
# activate 2.7 environment (if not in the directory of activate.bat, specify full path)
Invoke-CmdScript .\activate.bat py2
# deactivate 2.7 environment (same note about current directory and full paths)
Invoke-CmdScript .\deactivate.bat
If you want python 3 to run every time you type python3, and
python 2 to run every time you type python2:
Depending on where your executables are, simply make some aliases
using the following codes:
for python2:
Set-Alias python2 C:\Users\yourusername\python2location\python.exe
for python3:
Set-Alias python3 C:\Users\yourusername\python3location\python.exe
to learn how to make them permanent, check my response at the following page
From your PATH variable it appears you created the py27 env with the name "p27"
Try 'activate p27'
You can always double check the env names by looking in the "envs" directory in your conda installation folder.
A workaround if you love powershell compared to cmd without dealing with changing 'stuff' is to type:
cmd #to get internally into command prompt from ps
activate envname
powershell #to get back
Related
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>
source is a shell command designed for users running on Linux (or any Posix, but whatever, not Windows).
On Windows, virtualenv creates a .bat/.ps1 file, so you should run venv\Scripts\activate instead (per the virtualenv documentation on the activate script).
Just run activate, without an extension, so the right file will get used regardless of whether you're using cmd.exe or PowerShell.
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
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\activate
You can check it via spider tool in anaconda by typing import tensorflow as tf
For activation you can go to the venv your virtualenv directory
by cd venv.
Then on Windows, type dir (on unix, type ls).
You will get 5 folders include, Lib, Scripts, tcl and 60
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.
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.
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
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.
if you already cd your project type only in windows 10
Scripts/activate
That works for me:)
Tried several different commands until I came across:
source venv/Scripts/activate
This did it for me. Setup: Win 10, python 3.7, gitbash. Gitbash might be the culprit for not playing nice with other activate commands.
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
Open your powershell as admin
Enter "Set-ExecutionPolicy RemoteSigned -Force
Run "gpedit.msc" and go to >Administrative Templates>Windows Components>Windows Powershell
Look for "Activate scripts execution" and set it on "Activated"
Set execution directive to "Allow All"
Apply
Refresh your 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).
You can run the source command on cygwin terminal
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.
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
For windows Microsoft Tech Support it might be a problem with Execution Policy Settings. To fix it, you should try executing
Set-ExecutionPolicy Unrestricted -Scope Process
Finally Worked on Windows 10 by using:
activate myvenv
where myvenv is the name the virtual environment I want to activate.
So basically, the command is:
activate <<your_venv_name>>
All the best!
Some people are having trouble with vscode i assume as all the above methods dont work.
Its simply because by default vscode uses powershell not cmd...
click on the little arrow beside it and select cmd and run the command.
if .\venv\Scripts\activate does not work neither and you find this error
\Activate.ps1 cannot be loaded because running scripts is disabled on this system
you can simple type set-executionpolicy remotesigned in powershell and the error must be gone.
powershell should run as administrator
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.
If wants to open virtual environment on Windows then just remember one thing on giving path use backwards slash not forward.
This is right:
D:\xampp\htdocs\htmldemo\python-virtual-environment>env\Scripts\activate
This is wrong:
D:\xampp\htdocs\htmldemo\python-virtual-environment>env/Scripts/activate
The steps for activating virtualenv using Python3 on windows are:
python3 -m venv env
.\env\bin\activate
Use These it worked for meenv\Scripts\activate
For those of you crazy enough to have a custom DOS prompt, venv activation may fail, depending on your %PROMPT% environment variable content.
Say you have a DOS prompt defined as follows:
set PROMPT=$_$E[1;30;40m[$E[0;36;40m%computername% | %userdomain%\%username%$E[1;30;40m] $E[0;33;40m$M$_$E[35;40m$d$s$t$h$h$h$h$h$h$_$E[1;33;40m$p$_$E[1;30;40m$g $E[0;37;40m
(btw, it shows as follows, with some fancy colors:
[W10-MY_COMPUTER | W10-MY_COMPUTER\JOHNDOE]
15/09/2022 20:31
F:\
> echo "Hello World"
Hello World
[W10-MY_COMPUTER | W10-MY_COMPUTER\JOHNDOE]
15/09/2022 20:31
F:\
>
)
Then if you try to activate a venv :
.\venv\Scripts\activate.bat
it may fail with a rather unclear error that states:
Path not found
without further indications.
The trick is that activate.bat(/deactivate.bat) scripts try to save(/restore) the %PROMPT% variable with this syntax:
...
set _OLD_VIRTUAL_PROMPT=%PROMPT%
...
set PROMPT=(venv) %PROMPT%
...
It can be fixed with this syntax:
...
set "_OLD_VIRTUAL_PROMPT=%PROMPT%"
...
set "PROMPT=(venv) %PROMPT%"
...
now it shows:
[W10-MY_COMPUTER | W10-MY_COMPUTER\JOHNDOE]
15/09/2022 20:31
F:\
> venv\Scripts\activate.bat
(venv)
[W10-MY_COMPUTER | W10-MY_COMPUTER\JOHNDOE]
15/09/2022 20:31
F:\
>
Instead of using:
source ./venv/Scripts/activate
Use only:
./venv/Scripts/activate
Your Script will be activated.
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.
Open your project using VS code editor .
Change the default shell in vs code terminal to git bash.
now your project is open with bash console and right path, put
"source venv\Scripts\activate" in Windows
Navigate to your virtualenv folder eg ..\project1_env>
Then type
source scripts/activate
eg ..\project1_env>source scripts/activate
The best way is, using backward slahes and using .bat at the end of activate
C:\Users>your_env_name\Scripts\activate.bat
:: location of bat file
::C:\Users\gaojia\Dropbox\Projects\free_return\venv\Scripts\activate.bat
:: location of the cmd bat file and the ipython notebook
::C:\Users\gaojia\Dropbox\Projects\free_return\scripts\pre_analysis
source ..\..\venv\Scripts\activate
PAUSE
jupyter nbconvert --to html --execute consumer_response_DID.ipynb
PAUSE
Above is my bat file through which I try to execute an ipython notebook. But the cmd window gives me nothing and shut down instantly, any suggestion why would this happen?
Was just trying out making an environment via python and Django, but i keep running into this issue where the python interpreter does not seem to understand.
I have use source bin/activate as well, but to no avail.
.\test.com_env\Scripts\activate.ps1 :
The term '.\test.com_env\Scripts\activate.ps1' is not recognized
as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:1 char:1
.\test.com_env\Scripts\activate.ps1
Had the same problem on Windows 10. My solution was: From the outer folder to the virtual environment folder, I performed the following command line:
You can try:
.\test.com_env\Scripts\activate
I didn't have to add the extension.ps1.
You should check the location from where the above command line is being executed.
I just installed python on VS Code and I can't run any python code using python command.
python command:
Running the code seems to run python command by default and it does not recognize it.
When I right click and choose Run Code it complains:
'python' is not recognized as an internal or external command, operable program or batch file
Same goes for manually running python main.py.
When I open an elevated PowerShell and run python, it complains:
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
py command:
It doesn't try to use py command but it recognizes it. And when I manually call py main.py, it works.
When I manually do >py main.py it writes my Goodbye, World!
Question:
How can I make it compile/run in VS Code simply by using the CodeRunner's right-click feature (Run Code)?
I already have both Python folder and its Scripts folder in PATH.
I'm using VS Code 1.27.2 and I have installed python 3.7.0 on my machine and have checked its installer checkbox for adding the environment variables automatically. (PATH is ok)
I also installed : ms-python.python and tht13.python and formulahendry.code-runner extensions on the VS Code.
This is my main.py code:
print("Goodbye, World!")
It turned out that I just had to restart my computer after I installed ms-python.python and tht13.python and formulahendry.code-runner extensions on the VS Code and added python's Scripts folder in PATH.
Now both py and python commands work from anywhere like cmd or Run Code in the right click menu.
Restarting your PC after installing the Python Extension and changing the PATH to include Python and it's scripts folder will help. Worked for me
The Windows installer for Python does not put python on your path by default (there's a checkbox during installation to add it). Make sure that you selected an interpreter that's installed by running Select Interpreter and choosing the interpreter you want (the extension will find them through the registry).
I also had this problem after a fresh Windows reinstallation, vscode didnt recognize the commands like python or pip freeze in the PS terminal.
After reinstalling python and vscode, I read the tutorial for python for vscode: https://code.visualstudio.com/docs/python/python-tutorial. Creating a new venv worked for me py -3 -m venv .venv, then navigate to the venv: .venv\scripts\activate. In the new venv all the python commands worked as normal.
If you have already set the path variable, test the same command in a command prompt and see if it works. If it does, just update PowerShell's path settings by running the following from your vs code PowerShell terminal:
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" +
[System.Environment]::GetEnvironmentVariable("Path","User")`
This trick can save you a lot of restarts.
you need to first confirm if python is installed, for that just run python/python3 on terminal/cmd.
If it runs there and it isn't running in VS Code then restart your system in order to get changes reflected.
And if it doesn't run in terminal/cmd as well then first check if python's directories are placed in environment variables.
Add Python path (ex C:\Users\johndoe\AppData\Local\Programs\Python\Python39) to the %PATH% env variable
I added PATH and did everything. but it didn't work on Vscode Powershell.
but python was working in windows CMD. So I just reinstalled Vscode.
I'm running Anaconda 3 with Python 3.6 on MacOS 10.12.
I created an environment using python 2.7 and opencv using conda create --name my-env python=2.7 anaconda(e.g. here). I activated the environment using source activate my-env and installed opencv. Both creation and activation seem to have worked: the anaconda3/envs/my-env folder exists and my terminal says (my-env) bob:~ alice'.
But how do I get Anaconda to use the new environment?
I tried:
starting the default Anaconda-Navigator.app, this just uses the default python path
changing the path in my ~/.bash-profile, but Anaconda still tries the default python path
starting the Anaconda-Navigator.app located in the my-env folder, fails with the OS error message "cannot be opened"
starting from terminal exits with the error message: FSPathMakeRef(~/anaconda3/envs/my-env/Anaconda-Navigator) failed with error -43.
Because I read somewhere that Anaconda 3 might not play nicely with Python 2.7, I tried the same workflow again, but creating an environment using python 3.5.4. Again to no avail.
What am I missing?
there a two possibilities to run a program in an env once the env has been created with conda:
Through default anaconda-navigator (the GUI of anaconda), there should be a menu on the left, with the following options: Home, Environments, Projects(beta),...
Simply klick on environments and choose/create a new one(see screenshot)
The "Applications on base(root)" can also be changed. If it does not display these options I recommend you to update conda.
Via terminal: activate the env as you mentioned earlier and then simply run the program you want, for example spyder, it should then use the right py version.
My default version of anaconda, the "root(base)" runs with python 2, therefore I added a few lines in my .bash_profile file to easily run python/spyder in either a default env or a specific one. maybe you can use something similar.
NONE='\033[00m'
YELLOW='\033[01;33m'
spy() {
if [[ "${1}" == "" ]]
then
ENV="py36env"
else
ENV=${1}
fi
source activate ${ENV} #enter env
echo -e "${YELLOW}CURRENT ENVIRONMENT: ${ENV} ${NONE}"
spyder #open spyder
echo -e "${YELLOW}EXIT ${ENV} ${NONE}"
source deactivate #exit env when spyder is quitted
}
You can now run spyder in the env "XXX" by entering "spy XXX" in the terminal. Or the default one by typing in "spy".
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>
source is a shell command designed for users running on Linux (or any Posix, but whatever, not Windows).
On Windows, virtualenv creates a .bat/.ps1 file, so you should run venv\Scripts\activate instead (per the virtualenv documentation on the activate script).
Just run activate, without an extension, so the right file will get used regardless of whether you're using cmd.exe or PowerShell.
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
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\activate
You can check it via spider tool in anaconda by typing import tensorflow as tf
For activation you can go to the venv your virtualenv directory
by cd venv.
Then on Windows, type dir (on unix, type ls).
You will get 5 folders include, Lib, Scripts, tcl and 60
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.
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.
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
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.
if you already cd your project type only in windows 10
Scripts/activate
That works for me:)
Tried several different commands until I came across:
source venv/Scripts/activate
This did it for me. Setup: Win 10, python 3.7, gitbash. Gitbash might be the culprit for not playing nice with other activate commands.
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
Open your powershell as admin
Enter "Set-ExecutionPolicy RemoteSigned -Force
Run "gpedit.msc" and go to >Administrative Templates>Windows Components>Windows Powershell
Look for "Activate scripts execution" and set it on "Activated"
Set execution directive to "Allow All"
Apply
Refresh your 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).
You can run the source command on cygwin terminal
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.
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
For windows Microsoft Tech Support it might be a problem with Execution Policy Settings. To fix it, you should try executing
Set-ExecutionPolicy Unrestricted -Scope Process
Finally Worked on Windows 10 by using:
activate myvenv
where myvenv is the name the virtual environment I want to activate.
So basically, the command is:
activate <<your_venv_name>>
All the best!
Some people are having trouble with vscode i assume as all the above methods dont work.
Its simply because by default vscode uses powershell not cmd...
click on the little arrow beside it and select cmd and run the command.
if .\venv\Scripts\activate does not work neither and you find this error
\Activate.ps1 cannot be loaded because running scripts is disabled on this system
you can simple type set-executionpolicy remotesigned in powershell and the error must be gone.
powershell should run as administrator
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.
If wants to open virtual environment on Windows then just remember one thing on giving path use backwards slash not forward.
This is right:
D:\xampp\htdocs\htmldemo\python-virtual-environment>env\Scripts\activate
This is wrong:
D:\xampp\htdocs\htmldemo\python-virtual-environment>env/Scripts/activate
The steps for activating virtualenv using Python3 on windows are:
python3 -m venv env
.\env\bin\activate
Use These it worked for meenv\Scripts\activate
For those of you crazy enough to have a custom DOS prompt, venv activation may fail, depending on your %PROMPT% environment variable content.
Say you have a DOS prompt defined as follows:
set PROMPT=$_$E[1;30;40m[$E[0;36;40m%computername% | %userdomain%\%username%$E[1;30;40m] $E[0;33;40m$M$_$E[35;40m$d$s$t$h$h$h$h$h$h$_$E[1;33;40m$p$_$E[1;30;40m$g $E[0;37;40m
(btw, it shows as follows, with some fancy colors:
[W10-MY_COMPUTER | W10-MY_COMPUTER\JOHNDOE]
15/09/2022 20:31
F:\
> echo "Hello World"
Hello World
[W10-MY_COMPUTER | W10-MY_COMPUTER\JOHNDOE]
15/09/2022 20:31
F:\
>
)
Then if you try to activate a venv :
.\venv\Scripts\activate.bat
it may fail with a rather unclear error that states:
Path not found
without further indications.
The trick is that activate.bat(/deactivate.bat) scripts try to save(/restore) the %PROMPT% variable with this syntax:
...
set _OLD_VIRTUAL_PROMPT=%PROMPT%
...
set PROMPT=(venv) %PROMPT%
...
It can be fixed with this syntax:
...
set "_OLD_VIRTUAL_PROMPT=%PROMPT%"
...
set "PROMPT=(venv) %PROMPT%"
...
now it shows:
[W10-MY_COMPUTER | W10-MY_COMPUTER\JOHNDOE]
15/09/2022 20:31
F:\
> venv\Scripts\activate.bat
(venv)
[W10-MY_COMPUTER | W10-MY_COMPUTER\JOHNDOE]
15/09/2022 20:31
F:\
>
Instead of using:
source ./venv/Scripts/activate
Use only:
./venv/Scripts/activate
Your Script will be activated.
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.
Open your project using VS code editor .
Change the default shell in vs code terminal to git bash.
now your project is open with bash console and right path, put
"source venv\Scripts\activate" in Windows
Navigate to your virtualenv folder eg ..\project1_env>
Then type
source scripts/activate
eg ..\project1_env>source scripts/activate
The best way is, using backward slahes and using .bat at the end of activate
C:\Users>your_env_name\Scripts\activate.bat
:: location of bat file
::C:\Users\gaojia\Dropbox\Projects\free_return\venv\Scripts\activate.bat
:: location of the cmd bat file and the ipython notebook
::C:\Users\gaojia\Dropbox\Projects\free_return\scripts\pre_analysis
source ..\..\venv\Scripts\activate
PAUSE
jupyter nbconvert --to html --execute consumer_response_DID.ipynb
PAUSE
Above is my bat file through which I try to execute an ipython notebook. But the cmd window gives me nothing and shut down instantly, any suggestion why would this happen?