Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66756 > unrolled thread
| Started by | Piotr Dobrogost <p@google-groups-2014.dobrogost.net> |
|---|---|
| First post | 2014-02-20 06:27 -0800 |
| Last post | 2014-02-21 06:12 -0800 |
| Articles | 10 — 3 participants |
Back to article view | Back to comp.lang.python
Cross-platform way to get default directory for binary files like console scripts? Piotr Dobrogost <p@google-groups-2014.dobrogost.net> - 2014-02-20 06:27 -0800
Re: Cross-platform way to get default directory for binary files like console scripts? Ned Batchelder <ned@nedbatchelder.com> - 2014-02-20 10:11 -0500
Re: Cross-platform way to get default directory for binary files like console scripts? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-02-20 15:22 +0000
Re: Cross-platform way to get default directory for binary files like console scripts? Piotr Dobrogost <p@google-groups-2014.dobrogost.net> - 2014-02-20 07:34 -0800
Re: Cross-platform way to get default directory for binary files like console scripts? Ned Batchelder <ned@nedbatchelder.com> - 2014-02-20 10:42 -0500
Re: Cross-platform way to get default directory for binary files like console scripts? Piotr Dobrogost <p@google-groups-2014.dobrogost.net> - 2014-02-20 07:55 -0800
Re: Cross-platform way to get default directory for binary files like console scripts? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-02-20 15:44 +0000
Re: Cross-platform way to get default directory for binary files like console scripts? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-02-20 15:55 +0000
Re: Cross-platform way to get default directory for binary files like console scripts? Ned Batchelder <ned@nedbatchelder.com> - 2014-02-20 11:26 -0500
Re: Cross-platform way to get default directory for binary files like console scripts? Piotr Dobrogost <p@google-groups-2014.dobrogost.net> - 2014-02-21 06:12 -0800
| From | Piotr Dobrogost <p@google-groups-2014.dobrogost.net> |
|---|---|
| Date | 2014-02-20 06:27 -0800 |
| Subject | Cross-platform way to get default directory for binary files like console scripts? |
| Message-ID | <405ad1dc-691e-4c71-adfd-c19c599ad555@googlegroups.com> |
Hi! Is there cross-platform way to get default directory for binary files (console scripts for instance) the same way one can use sys.executable to get path to the Python's interpreter in cross-platform way? Context: There's Python script which runs various tools like pip using subprocess and we would like to make sure we run tools that accompany Python's interpreter used to run this script. Please note that the script may be run from within virtualenv which had not been activated - ./venv/bin/python our_script.py Regards, Piotr Dobrogost
[toc] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-02-20 10:11 -0500 |
| Message-ID | <mailman.7187.1392909097.18130.python-list@python.org> |
| In reply to | #66756 |
On 2/20/14 9:27 AM, Piotr Dobrogost wrote: > Hi! > > Is there cross-platform way to get default directory for binary files (console scripts for instance) the same way one can use sys.executable to get path to the Python's interpreter in cross-platform way? > > Context: > There's Python script which runs various tools like pip using subprocess and we would like to make sure we run tools that accompany Python's interpreter used to run this script. Please note that the script may be run from within virtualenv which had not been activated - ./venv/bin/python our_script.py > > > Regards, > Piotr Dobrogost > Hi Piotr, we talked about this briefly in #python this morning. I still don't quite understand why you are averse to activating the virtualenv. It is designed to solve precisely this problem: create an environment that uses the natural OS tools (including PATH) to produce a consistent environment that works the way tools expect. If you don't activate the virtualenv, then you can look for your Python executable using sys.executable, and see if the file you want to run is in that same directory. I have no idea under what conditions that is the right or wrong answer, and I don't know what to do if the file you're looking for isn't in that directory. Perhaps the shorter answer is, look in the Python executable directory, then look in the directories on PATH. -- Ned Batchelder, http://nedbatchelder.com
[toc] | [prev] | [next] | [standalone]
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2014-02-20 15:22 +0000 |
| Message-ID | <mailman.7188.1392909800.18130.python-list@python.org> |
| In reply to | #66756 |
On 20 February 2014 14:27, Piotr Dobrogost <p@google-groups-2014.dobrogost.net> wrote: > Is there cross-platform way to get default directory for binary files (console scripts for instance) the same way one can use sys.executable to get path to the Python's interpreter in cross-platform way? > > Context: > There's Python script which runs various tools like pip using subprocess and we would like to make sure we run tools that accompany Python's interpreter used to run this script. Please note that the script may be run from within virtualenv which had not been activated - ./venv/bin/python our_script.py I'm not sure if I understand the question. Are you trying to find where a script would go if it had been installed as a result of 'python setup.py install' or 'pip install ...'? If so there are different places it could go depending not only on the system but also how the packages were installed (e.g. --user). You can find the default location in this roundabout way: In [1]: from distutils.command.install import install In [2]: from distutils.dist import Distribution In [3]: c = install(Distribution()) In [4]: c.finalize_ c.finalize_options c.finalize_other c.finalize_unix In [4]: c.finalize_options() In [5]: c.insta c.install_base c.install_headers c.install_lib c.install_path_file c.install_platlib c.install_scripts c.install_usersite c.install_data c.install_layout c.install_libbase c.install_platbase c.install_purelib c.install_userbase In [5]: c.install_scripts Out[5]: '/usr/local/bin' Oscar
[toc] | [prev] | [next] | [standalone]
| From | Piotr Dobrogost <p@google-groups-2014.dobrogost.net> |
|---|---|
| Date | 2014-02-20 07:34 -0800 |
| Message-ID | <991f7bda-7313-4192-9e56-410a454b79d8@googlegroups.com> |
| In reply to | #66760 |
On Thursday, February 20, 2014 4:22:53 PM UTC+1, Oscar Benjamin wrote: > > I'm not sure if I understand the question. Are you trying to find > where a script would go if it had been installed as a result of > 'python setup.py install' or 'pip install ...'? > Yes. > If so there are > different places it could go depending not only on the system but also > how the packages were installed (e.g. --user). Right. > You can find the default location in this roundabout way: > > (...) > > In [5]: c.install_scripts > Out[5]: '/usr/local/bin' I think this is pretty much what I'm after, thanks. I'm wondering if there's some API to get this info as what you showed is really roundabout way to achieve the goal... Regards, Piotr
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-02-20 10:42 -0500 |
| Message-ID | <mailman.7190.1392910988.18130.python-list@python.org> |
| In reply to | #66762 |
On 2/20/14 10:34 AM, Piotr Dobrogost wrote:
> On Thursday, February 20, 2014 4:22:53 PM UTC+1, Oscar Benjamin wrote:
>>
>> I'm not sure if I understand the question. Are you trying to find
>> where a script would go if it had been installed as a result of
>> 'python setup.py install' or 'pip install ...'?
>
>> Yes.
>
>> If so there are
>> different places it could go depending not only on the system but also
>> how the packages were installed (e.g. --user).
>
> Right.
>
>> You can find the default location in this roundabout way:
>>
>> (...)
>>
>> In [5]: c.install_scripts
>> Out[5]: '/usr/local/bin'
>
> I think this is pretty much what I'm after, thanks.
> I'm wondering if there's some API to get this info as what you showed is really roundabout way to achieve the goal...
As roundabout and advanced as that code is, it doesn't give the right
answer for me. It returns None. On my Mac, after activating a virtualenv:
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.command.install import install
>>> from distutils.dist import Distribution
>>> c = install(Distribution())
>>> c.install_scripts
>>> c.install_scripts is None
True
>>> sys.executable
'/usr/local/virtualenvs/studygroup/bin/python'
>>> os.listdir(os.path.dirname(sys.executable))
['activate', 'activate.csh', 'activate.fish', 'activate_this.py',
'easy_install', 'easy_install-2.7', 'pip', 'pip-2.7', 'python',
'python2', 'python2.7']
>>>
--
Ned Batchelder, http://nedbatchelder.com
[toc] | [prev] | [next] | [standalone]
| From | Piotr Dobrogost <p@google-groups-2014.dobrogost.net> |
|---|---|
| Date | 2014-02-20 07:55 -0800 |
| Message-ID | <e0a1a813-83ff-4c9c-8d47-829aba1d9ded@googlegroups.com> |
| In reply to | #66763 |
On Thursday, February 20, 2014 4:42:54 PM UTC+1, Ned Batchelder wrote: > > As roundabout and advanced as that code is, it doesn't give the right > answer for me. It returns None. Indeed. I tried on Linux and got None both inside and outside virtualenv :( Regards, Piotr
[toc] | [prev] | [next] | [standalone]
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2014-02-20 15:44 +0000 |
| Message-ID | <mailman.7191.1392911120.18130.python-list@python.org> |
| In reply to | #66762 |
On 20 February 2014 15:34, Piotr Dobrogost <p@google-groups-2014.dobrogost.net> wrote: > On Thursday, February 20, 2014 4:22:53 PM UTC+1, Oscar Benjamin wrote: > >> You can find the default location in this roundabout way: > > I'm wondering if there's some API to get this info as what you showed is really roundabout way to achieve the goal... There may be something that I don't know of. Distutils is generally pretty clunky though if you're not trying to do one of the exact things it was designed to do. Oscar
[toc] | [prev] | [next] | [standalone]
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2014-02-20 15:55 +0000 |
| Message-ID | <mailman.7193.1392911764.18130.python-list@python.org> |
| In reply to | #66762 |
On 20 February 2014 15:42, Ned Batchelder <ned@nedbatchelder.com> wrote: > > As roundabout and advanced as that code is, it doesn't give the right answer > for me. It returns None. On my Mac, after activating a virtualenv: > > Python 2.7.2 (default, Oct 11 2012, 20:14:37) > [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on > darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> from distutils.command.install import install > >>> from distutils.dist import Distribution > >>> c = install(Distribution()) You forgot to call c.finalize_options() here which actually sets all of these attributes. > >>> c.install_scripts > >>> c.install_scripts is None > True Oscar
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-02-20 11:26 -0500 |
| Message-ID | <mailman.7194.1392913610.18130.python-list@python.org> |
| In reply to | #66762 |
On 2/20/14 10:55 AM, Oscar Benjamin wrote: > On 20 February 2014 15:42, Ned Batchelder <ned@nedbatchelder.com> wrote: >> >> As roundabout and advanced as that code is, it doesn't give the right answer >> for me. It returns None. On my Mac, after activating a virtualenv: >> >> Python 2.7.2 (default, Oct 11 2012, 20:14:37) >> [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on >> darwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>> from distutils.command.install import install >> >>> from distutils.dist import Distribution >> >>> c = install(Distribution()) > > You forgot to call c.finalize_options() here which actually sets all > of these attributes. > Ah, good! Thanks! -- Ned Batchelder, http://nedbatchelder.com
[toc] | [prev] | [next] | [standalone]
| From | Piotr Dobrogost <p@google-groups-2014.dobrogost.net> |
|---|---|
| Date | 2014-02-21 06:12 -0800 |
| Message-ID | <dbf565d9-bd38-4dc6-a9f5-04f8c9693059@googlegroups.com> |
| In reply to | #66762 |
On Thursday, February 20, 2014 4:34:25 PM UTC+1, Piotr Dobrogost wrote: > > I'm wondering if there's some API to get this info as what you showed is really roundabout way to achieve the goal... Turns out there is API for this - see thread on distutils-sig mailing list at https://mail.python.org/pipermail/distutils-sig/2014-February/023867.html Regards, Piotr Dobrogost
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web