Skip to content

Make VENV_DIR relative to Script directory #71335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
beadle mannequin opened this issue May 29, 2016 · 2 comments
Closed

Make VENV_DIR relative to Script directory #71335

beadle mannequin opened this issue May 29, 2016 · 2 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@beadle
Copy link
Mannequin

beadle mannequin commented May 29, 2016

BPO 27148
Nosy @vsajip, @beadle

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-05-31.07:24:18.409>
created_at = <Date 2016-05-29.03:57:34.934>
labels = ['type-feature', 'library']
title = 'Make VENV_DIR relative to Script directory'
updated_at = <Date 2016-05-31.07:24:18.408>
user = 'https://github.com/beadle'

bugs.python.org fields:

activity = <Date 2016-05-31.07:24:18.408>
actor = 'vinay.sajip'
assignee = 'none'
closed = True
closed_date = <Date 2016-05-31.07:24:18.409>
closer = 'vinay.sajip'
components = ['Library (Lib)']
creation = <Date 2016-05-29.03:57:34.934>
creator = 'widmo'
dependencies = []
files = []
hgrepos = []
issue_num = 27148
keywords = []
message_count = 2.0
messages = ['266583', '266742']
nosy_count = 2.0
nosy_names = ['vinay.sajip', 'widmo']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue27148'
versions = ['Python 3.6']

@beadle
Copy link
Mannequin Author

beadle mannequin commented May 29, 2016

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

@beadle beadle mannequin added the type-feature A feature request or enhancement label May 29, 2016
@SilentGhost SilentGhost mannequin added the stdlib Python modules in the Lib dir label May 29, 2016
@vsajip
Copy link
Member

vsajip commented May 31, 2016

Thanks for the suggestion, but I don't propose to change the way things work in this area, for the following reasons:

  1. pyvenv tries to use the same directory layout/location of scripts as virtualenv does. This allows users who are used to virtualenv to have less to think about when switching to pyvenv.
  2. Virtual environments (venvs) aren't meant to be movable. Scripts installed into virtual environments have the venv's absolute path hard-coded into their shebang. This is true for both virtualenv and pyvenv. However, a venv can always be created at another location and have the same stuff installed into it, and the old venv discarded.
  3. Making changes like this would not be backwards compatible - they would probably break existing code which relies on a common layout between virtualenv and pyvenv, or the existing relative locations of script files.

@vsajip vsajip closed this as completed May 31, 2016
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant