473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PYTHONSITEDIR environment variable

ago
Dear all,

These days I often find myself using working-env.py, virtual-python.py
& co. The main reason in most cases is to insulate my working
environment so that I can use custom site-package libs together with
the default stdlib. PYTHONHOME and/or PYTHONPATH (particularly with
python -S) get close, but not quite there, and the above scripts seem
a bit over the top.

Wouldn't it be possible to support a PYTHONSITEDIR environment
variable in site.py for this purpose? I have attached a possible
patch. In what follows, if PYTHONSITEDIR is defined, that dir is used
as the only source of site-packages, extra paths can easily be added
by creating a .pth file in there. A different variable could be used
to prepend a sitedir to the list of default sitedirs (similar code
without "return None").
--- /usr/lib/python2.5/site.py 2008-05-29 22:03:04.000000000 +0100
+++ /tmp/site.py 2008-09-09 18:06:42.000000000 +0100
@@ -167,6 +167,10 @@

def addsitepackages(known_paths):
"""Add site-packages (and possibly site-python) to sys.path"""
+ sitedir = os.environ.get('PYTHONSITEDIR')
+ if sitedir and os.path.isdir(sitedir):
+ addsitedir(sitedir, known_paths)
+ return None
prefixes = [sys.prefix]
if sys.exec_prefix != sys.prefix:
prefixes.append(sys.exec_prefix)
Sep 9 '08 #1
5 1893
ago wrote:
Wouldn't it be possible to support a PYTHONSITEDIR environment
variable in site.py for this purpose? I have attached a possible
patch. In what follows, if PYTHONSITEDIR is defined, that dir is used
as the only source of site-packages, extra paths can easily be added
by creating a .pth file in there. A different variable could be used
to prepend a sitedir to the list of default sitedirs (similar code
without "return None").
I had a similar idea, wrote a PEP and implemented it for 2.6 and 3.0:

http://www.python.org/dev/peps/pep-0370/

Christian
Sep 9 '08 #2
ago
On Sep 9, 6:56*pm, Christian Heimes <li...@cheimes.dewrote:
I had a similar idea, wrote a PEP and implemented it for 2.6 and 3.0:

http://www.python.org/dev/peps/pep-0370/

Christian
Christian,

I like your pep :),

The only thing I would add is that in my experience I often use
different working-envs for different projects, so I'd prefer to have a
more generic solution as opposed to a single working-env per user. The
latter could still be achieved by setting the appropriate environment
variable in the user profile. Do you think it would be possible to
accommodate for the above in your PEP?
Sep 9 '08 #3
ago wrote:
The only thing I would add is that in my experience I often use
different working-envs for different projects, so I'd prefer to have a
more generic solution as opposed to a single working-env per user. The
latter could still be achieved by setting the appropriate environment
variable in the user profile. Do you think it would be possible to
accommodate for the above in your PEP?
Isn't PYTHONUSERBASE sufficient for your needs? The env var alters the
base directory.

I can neither change the PEP nor the implementation at this stage of the
development cycle. Python 2.6 and 3.0 are in beta and the API is set in
stone.

Christian

Sep 9 '08 #4
ago
Small variation on the above patch, using 2 environment variables:
PYTHONSITEDIR allows for local site-packages (that override system
site packages), and PYTHONNOSYSSITES skips system site-packages for
"clean-room" operation (similar to virtual-python.py --no-site-
packages).
--- /usr/lib/python2.5/site.py 2008-05-29 22:03:04.000000000 +0100
+++ /tmp/site.py 2008-09-09 19:56:44.000000000 +0100
@@ -167,6 +167,11 @@

def addsitepackages(known_paths):
"""Add site-packages (and possibly site-python) to sys.path"""
+ sitedir = os.environ.get('PYTHONSITEDIR')
+ if sitedir and os.path.isdir(sitedir):
+ addsitedir(sitedir, known_paths)
+ if os.environ.get('PYTHONNOSYSSITES'):
+ return None
prefixes = [sys.prefix]
if sys.exec_prefix != sys.prefix:
prefixes.append(sys.exec_prefix)
Sep 9 '08 #5
ago
On Sep 9, 7:45*pm, Christian Heimes <li...@cheimes.dewrote:
ago wrote:
The only thing I would add is that in my experience I often use
different working-envs for different projects, so I'd prefer to have a
more generic solution as opposed to a single working-env per user. The
latter could still be achieved by setting the appropriate environment
variable in the user profile. Do you think it would be possible to
accommodate for the above in your PEP?

Isn't PYTHONUSERBASE sufficient for your needs? The env var alters the
base directory.

I can neither change the PEP nor the implementation at this stage of the
development cycle. Python 2.6 and 3.0 are in beta and the API is set in
stone.

Christian

I had missed that, yes I think that PYTHONUSERBASE will do fine!
It might be useful though to be able to skip other system site dirs
altogether so that only local site packages are used, as in the second
patch I sent (see PYTHONNOSYSSITES).

Thanks a lot,

Ago
Sep 9 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: could ildg | last post by:
To a environment variable in Windows, can python know if it is a system environment variable or a current-user environment variable? -- ðÐðÄ´ÏÃ÷¾ø¶¥¡¢¸ãЦ֮¼«£¬ÊÇÈËÀàµÄºÃÅóÓÑ¡£...
28
by: Christian | last post by:
Another question from a not even newbie: In Unix you can set an environment variable with the command export PYTHONPATH but I would like to set the variable from at .py script. So my question...
13
by: Jimmy Cracker | last post by:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: main(int argc, char *argv) { char *var; var = (char...
1
by: Bonj | last post by:
Hi My application installs a front-end GUI, which runs code when buttons are clicked. It also installs a command-line utility, that is a console application. They are both installed to the...
4
by: | last post by:
Hi all, I am trying to append a certain string to the PATH environment variable programmatically. I am able to read what is in the variable using the System.Environment method...
6
by: yaron | last post by:
Hi, my application use environment variable, let call it FOO. how can i add the FOO environment variable to my project or my solution, so the line string foo =...
0
by: Joe HM | last post by:
Hello - I am putting together a little ConsoleApplication that is supposed to check for an Environment Variable and create it if it does not exist. I found some code that will add a new...
4
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment...
4
by: vkbishnoi | last post by:
I need to create an environment variable for another local user in windows. For example, say suppose there are 2 users in the system (User1 and User2). Currently User1 is logged in the system. Now Is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.