Activating pyvenv from gitbash for windows

此生再无相见时 提交于 2019-12-03 06:25:25

There were lots of confusion in many answers and comments here. Some of them said you can simply do . activate, some (@nme) said "You'll get the "No such file or directory" error then since there is only activate.bat and Activate.ps1 which both don't work."

The problem did exist, as documented in this issue. And that issue was eventually fixed at Jan 2017 in Python 3.5.x, 3.6.x onward. Therefore, ONLY Python 3.5.3+, 3.6.1+, 3.7 released AFTER Jan 2017 would have fixed such issue. Possibly Python 2.7.14+ too. This means, if you are still reading this Q&A page, the first thing you would need to do is to check which version of Python you are using, and then probably do an upgrade. (For example, I encountered same issue with one of my old Python 3.6.0 environment, and after upgrading to Python 3.7.2, the problem is gone.)

Nwawel A Iroume

You do not have to worry about the presence of virtual env bash script go to Git bash and use . Scripts/activate or source Scripts/activate as mentioned in answer in this topic Can not activate a virtualenv in GIT bash mingw32 for Windows

This is (currently) by design.

In Windows, only the Command Prompt (.bat) and PowerShell (.ps1) scripts are installed. The venv documentation says "The invocation of the script is platform-specific" – see the table in that document listing commands to activate the venv on different platforms. If you look at the venv source code, you can see that it differentiates between Windows and POSIX environments and installs scripts accordingly.

However, there is an open bug that requests that scripts for other shells should also be installed. While waiting for that to possibly be resolved, there is a workaround: you could grab the bash (or other shell) script from your local machine or from the cPython hg repository (direct link to the file) and put it in the Scripts folder next to the Windows-specific ones. You need to change __VENV_DIR__ to the directory where your venv is located, __VENV_BIN_NAME__ to "bin", and __VENV_PROMPT__ to whatever you want the bash prompt to be when the venv is activated (for example, "(env) "). Set permissions, and you should be good to go.

The following code explain how to set up and start a virtualenv named env_project inside a folder named project in Git Bash:

mkdir project
cd project/
virtualenv env_project
. activate env_project/
Diego Santa Cruz Mendezú

this worked for me:

. activate
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!