Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 3382  / 2 Years ago, fri, march 18, 2022, 7:49:24

Problem:


The bin directory of my virtual environment produced with virtualenvwrapper (which uses virtualenv under the hood) is located in the subfolderlocal instead which leads to breakage across the board (mostly virtualenvwrapper and vscode for now).
Basically, these tools expect the interpreter in <envname>/bin and not in <envname>/local/bin.


Infos:


I already did some research and found the following:



  • There was a change in Ubuntu 22.04 that now uses posix_local in module sysconfig instead of posix_prefix as the default scheme which was explained here

  • Virtualenv at some point introduced a patch for Python 2 that changed the bin location to local/bin inside a virtual environment in response to the posix_local prefix, which was asked in this question and resulted in this patch which was supposed to fix this bug


System:



  • Ubuntu 22.04 LTS x86_64

  • python3 - 3.10.4-0ubuntu2

  • python3-virtualenv - 20.13.0+ds-2

  • virtualenvwrapper==4.8.4


Question:



  • How do I get virtualenv to install my environment into <envname>/bin again, ignoring posix_local option?

  • Is the reason why this was fixed still applicable for Python 3? (I must admit I did not really understand the reason why the patch was necessary in the first place.)


More From » python3

 Answers
0

Original Answer


The user yingmanwumen over on the GitHub of virtualenv posted a solution in this issue:


Basically, they changed the sysconfig scheme by exporting the following variable in their shell of choice:


export DEB_PYTHON_INSTALL_LAYOUT='deb'

This changes the default installation scheme from posix_local, which produced the problematic behavior, to deb_system, which has the normal/expected virtual environment layout again.
The current installation scheme can be checked with this snipped:


import sysconfig
print(sysconfig.get_default_scheme())

It should be noted that this is a temporary solution.
A real solution would probably include changing this behavior in virtualenv itself. yingmanwumen's issue as well as my own issue address problems with the posix_local scheme. The developers of virtualenv are open to accepting a PR to resolve the underlying issue.
I will update this answer if a PR is proposed and accepted that resolves it.




Update


A PR was accepted solving this issue specifically for virtualenv, meaning that all versions of virtualenv > 20.16.5 should not have this problem anymore.


Additionally, it seems the bug happens specifically if:



[...] python3-distutils is not installed (or when not using the deadsnakes fork)



according to the proposer of the PR.
So either installing python3-distutils or using the version of the deadsnakes fork should also fix this problem if it is encountered.


Lastly, efforts are taken to address this issue also in Debian/Ubuntu and with making the posix_prefix scheme more robust in general. This wasn't the first issue that happened due to confusing installation schemes as can be seen in this discussion.


[#564] Saturday, March 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
onbean

Total Points: 29
Total Questions: 102
Total Answers: 115

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
onbean questions
Tue, Dec 6, 22, 11:51, 1 Year ago
Mon, Jun 7, 21, 17:21, 3 Years ago
Mon, Jan 16, 23, 04:48, 1 Year ago
Mon, Oct 17, 22, 14:51, 2 Years ago
;