472,976 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,976 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 1876
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.