Message266583
I would like to see some enhancement where the activate.bat and activate scripts allow the script to determine where the python executable resides.
When the executable cannot be found (because the path doesn't exist for some reason), the system will ultimately find the installed version of python. This can cause side effects that may be non-obvious to users.
Example:
User creates a virtual environment:
python -m venv C:\Location\To\Project venv
User manually changes location of project:
xcopy /E C:\Location\To\Project C:\New\Project\Location
User runs activate.bat:
(venv) C:\New\Project\Location
At this point, the user will get the modified prompt, but will
actually be using his/her globally installed python. Therefore,
running anything like pip will taint their install. Further, if
they had set up the environment previously, it can cause errors
because modules won't be found (because it's pointing at the
wrong Lib\site-packages folder).
Code:
activate.bat
;Replace set "VIRTUAL_ENV=__VENV_DIR__"
set "VIRTUAL_ENV=%~dp0..\"
activate
FILE=$(readlink -f "$0")
FILE_DIR=$(dirname "$FILE")
# Replace VIRTUAL_ENV="__VENV_DIR__"
VIRTUAL_ENV="$FILE_DIR/../"
Somewhat related, I've also found that's it's incredibly convenient to also include activate and deactivate files at the root of the venv:
python -m venv C:\project venv
# Now, C:\project looks like this:
.\venv
.\activate.bat
.\deactivate.bat
# activate and deactivate are very simple:
;activate.bat
@ECHO OFF
pushd env\Scripts
call activate
popd
;deactivate.bat
@ECHO OFF
pushd env\Scripts
call deactivate
popd |
|
Date |
User |
Action |
Args |
2016-05-29 03:57:35 | widmo | set | recipients:
+ widmo |
2016-05-29 03:57:35 | widmo | set | messageid: <1464494255.1.0.144712628992.issue27148@psf.upfronthosting.co.za> |
2016-05-29 03:57:34 | widmo | link | issue27148 messages |
2016-05-29 03:57:32 | widmo | create | |
|