View previous topic :: View next topic |
Author |
Message |
3PO Veteran


Joined: 26 Nov 2006 Posts: 1110 Location: Schwabenländle
|
Posted: Sat Jan 12, 2019 6:23 pm Post subject: [SOLVED] Wie temporär die Python Version ändern? |
|
|
Wie kann man denn temporär die zu verwendete Python Version ändern?
Mir ist schon klar, dass es mit "eselect Python set ..." geht, aber wie mache ich das z.B. in einem BASH Script?
Last edited by 3PO on Sat Jan 12, 2019 8:23 pm; edited 1 time in total |
|
Back to top |
|
 |
firefly Watchman

Joined: 31 Oct 2002 Posts: 5340
|
Posted: Sat Jan 12, 2019 6:36 pm Post subject: |
|
|
indem du statt python pythonx.y schreibst z.b. python3.5 für python 3.5 _________________ Ein Ring, sie zu knechten, sie alle zu finden,
Ins Dunkel zu treiben und ewig zu binden
Im Lande Mordor, wo die Schatten drohn. |
|
Back to top |
|
 |
3PO Veteran


Joined: 26 Nov 2006 Posts: 1110 Location: Schwabenländle
|
Posted: Sat Jan 12, 2019 6:41 pm Post subject: |
|
|
Das geht leider nicht immer.
Wenn es sich nur um einen einfache Befehl handeln würde, wäre das OK.
Ich müsste aber die Version während der ganze Sitzung ändern. |
|
Back to top |
|
 |
firefly Watchman

Joined: 31 Oct 2002 Posts: 5340
|
|
Back to top |
|
 |
3PO Veteran


Joined: 26 Nov 2006 Posts: 1110 Location: Schwabenländle
|
Posted: Sat Jan 12, 2019 7:06 pm Post subject: |
|
|
Ich experimentiere gerade damit.
Und ich möchte nicht jedes mal mit eselect die Python Version switchen müssen. |
|
Back to top |
|
 |
mike155 Advocate

Joined: 17 Sep 2010 Posts: 4438 Location: Frankfurt, Germany
|
Posted: Sat Jan 12, 2019 7:42 pm Post subject: |
|
|
Ich verstehe die Fragestellung noch nicht ganz.
1) Willst Du aus einem bash Script mehrere Python Programme mit einer anderen Python Version aufrufen?
2) Oder ist das Problem, dass Du ein Programm aufrufen möchtest, das weitere Sub-Programme aufruft und Du kontrollieren möchtest, mit welcher Version von Python die Sub-Programme laufen?
Für 1) gibt es eine triviale Lösung. Für 2) gibt es vermutlich keine universelle Lösung. Es hängt stark davon ab, wie das Programm die Sub-Programm aufruft. Wenn es beispielsweise ein Aufruf "python subprogram.py" ist, kannst Du das Problem mit der PATH Umgebungsvariable und einem eigenen Python Link lösen.
Last edited by mike155 on Sat Jan 12, 2019 7:50 pm; edited 1 time in total |
|
Back to top |
|
 |
Josef.95 Advocate

Joined: 03 Sep 2007 Posts: 4740 Location: Germany
|
Posted: Sat Jan 12, 2019 7:50 pm Post subject: |
|
|
Hm, ich bin mir nicht sicher ob das in einem Script brauchbar ist, aber auf der Kommandozeile nutze ich für sowas meist EPYTHON=
Beispiel: | EPYTHON=python2.7 emerge -V |
|
|
Back to top |
|
 |
3PO Veteran


Joined: 26 Nov 2006 Posts: 1110 Location: Schwabenländle
|
Posted: Sat Jan 12, 2019 7:57 pm Post subject: |
|
|
THX @josef.95,
genau das hatte ich gesucht.
Mit "export" funktioniert das hervorragend:
Code: | server01 ~ # python -V
Python 3.6.5
server01 ~ # export EPYTHON=python2.7
server01 ~ # python -V
Python 2.7.15
server01 ~ # |
|
|
Back to top |
|
 |
mike155 Advocate

Joined: 17 Sep 2010 Posts: 4438 Location: Frankfurt, Germany
|
Posted: Sat Jan 12, 2019 8:55 pm Post subject: |
|
|
Guter Tipp! Das kannte ich noch nicht.
In /usr/share/doc/python-exec-2.4.6/README.bz2 steht folgende Doku dazu:
Quote: | [...]
python-exec supports two configuration layers: EPYTHON environment variable and a configuration file.
The EPYTHON environment variable can be used to configure python-exec at runtime and/or override local configuration. If it is defined, it specifies the most preferred Python interpreter that should be used to run the script. If the specified interpreter is unsupported by the script, python-exec will fall back to configuration file and/or default order.
[...] |
|
|
Back to top |
|
 |
|