Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Wie temporär die Python Version ändern?
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Sat Jan 12, 2019 6:23 pm    Post subject: [SOLVED] Wie temporär die Python Version ändern? Reply with quote

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
View user's profile Send private message
firefly
Watchman
Watchman


Joined: 31 Oct 2002
Posts: 5175

PostPosted: Sat Jan 12, 2019 6:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Sat Jan 12, 2019 6:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
firefly
Watchman
Watchman


Joined: 31 Oct 2002
Posts: 5175

PostPosted: Sat Jan 12, 2019 6:53 pm    Post subject: Reply with quote

hast du mal ein beispiel?

ansonsten mit einem alias: https://askubuntu.com/questions/699162/using-different-version-of-python

oder hiermit: https://medium.freecodecamp.org/manage-multiple-python-versions-and-virtual-environments-venv-pyenv-pyvenv-a29fb00c296f?gi=8c769e88bcd8

gefunden mit suche "python select version per session"
_________________
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
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Sat Jan 12, 2019 7:06 pm    Post subject: Reply with quote

Ich experimentiere gerade damit.

Und ich möchte nicht jedes mal mit eselect die Python Version switchen müssen.
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Sat Jan 12, 2019 7:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
Josef.95
Advocate
Advocate


Joined: 03 Sep 2007
Posts: 4549
Location: Germany

PostPosted: Sat Jan 12, 2019 7:50 pm    Post subject: Reply with quote

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
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Sat Jan 12, 2019 7:57 pm    Post subject: Reply with quote

THX @josef.95,

genau das hatte ich gesucht. :wink:

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
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Sat Jan 12, 2019 8:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum