Skip to content
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

User Site Dir not Found #171

Closed
theonejb opened this issue Sep 11, 2011 · 2 comments
Closed

User Site Dir not Found #171

theonejb opened this issue Sep 11, 2011 · 2 comments

Comments

@theonejb
Copy link

There seems to be an issue with the way virtualenv locates the users site dir. While I have also seen the same issue on Linux (openSuse 11.4), I have only been able to test thoroughly on Mac OS X Lion.

uname output

Darwin asad-macbook 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11 PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64

In the lib/site.py for both the Apples version of Python (at /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7) and the MacPorts version (at /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7) use the following function to find the user dir:

def addusersitepackages(known_paths):
"""Add a per user site-package to sys.path

Each user has its own python directory with site-packages in the
home directory.
"""
# get the per user site-package path
# this call will also make sure USER_BASE and USER_SITE are set
user_site = getusersitepackages()

if ENABLE_USER_SITE and os.path.isdir(user_site):
    addsitedir(user_site, known_paths)
return known_paths

But inside the virtualenv, the lib/site.py uses:

def addusersitepackages(known_paths):
"""Add a per user site-package to sys.path

Each user has its own python directory with site-packages in the
home directory.

USER_BASE is the root directory for all Python versions

USER_SITE is the user specific site-packages directory

USER_SITE/.. can be used for data.
"""
global USER_BASE, USER_SITE, ENABLE_USER_SITE
env_base = os.environ.get("PYTHONUSERBASE", None)

def joinuser(*args):
    return os.path.expanduser(os.path.join(*args))

#if sys.platform in ('os2emx', 'riscos'):
#    # Don't know what to put here
#    USER_BASE = ''
#    USER_SITE = ''
if os.name == "nt":
    base = os.environ.get("APPDATA") or "~"
    if env_base:
        USER_BASE = env_base
    else:
        USER_BASE = joinuser(base, "Python")
    USER_SITE = os.path.join(USER_BASE,
                             "Python" + sys.version[0] + sys.version[2],
                             "site-packages")
else:
    if env_base:
        USER_BASE = env_base
    else:
        USER_BASE = joinuser("~", ".local")
    USER_SITE = os.path.join(USER_BASE, "lib",
                             "python" + sys.version[:3],
                             "site-packages")

if ENABLE_USER_SITE and os.path.isdir(USER_SITE):
    addsitedir(USER_SITE, known_paths)
if ENABLE_USER_SITE:
    for dist_libdir in ("lib", "local/lib"):
        user_site = os.path.join(USER_BASE, dist_libdir,
                                 "python" + sys.version[:3],
                                 "dist-packages")
        if os.path.isdir(user_site):
            addsitedir(user_site, known_paths)
return known_paths

Which uses ~/,local as the USER_BASE, whereas on my system, the USER_BASE should be ~/Library/... I have also seen the same problem on my Linux (openSuse) machine.

@chaoflow
Copy link

This at least sounds related to #369 and #245.

@stale
Copy link

stale bot commented Jan 15, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just add a comment if you want to keep it open. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 15, 2019
@stale stale bot closed this as completed Jan 22, 2019
@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants