Python Forum
How could i change the python interpreter path of os.system()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How could i change the python interpreter path of os.system()
#1
print(sys.executable) ==> /opt/tools/anaconda3/bin/python3
but
os.system("which python") ==> /usr/bin/python

How could i change the python interpreter path of os.system() to "/opt/tools/anaconda3/bin/python3" ?
Reply
#2
This really isn't a Python question. The shell will look for executables by searching the directories in the PATH environment variable in order. So, put the one you prefer to use earlier in the PATH than /usr/bin. It would help to know which shell you're using.
Reply
#3
Don't try to modify your environment, instead modify your program.
import sys
from subprocess import Popen


proc = Popen([sys.executable, "your_script.py"])
return_value = proc.wait()  # this call blocks until the program has been finished
Don't use os.system, it's deprecated since years.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mac default python interpreter Viewpoint8455 2 910 Oct-13-2022, 06:25 AM
Last Post: perfringo
  change backslash into slash in a path paul18fr 7 2,338 Jul-21-2022, 04:26 PM
Last Post: deanhystad
  Python Interpreter ankitdixit 4 2,695 Jun-10-2022, 12:37 PM
Last Post: katy1234
Photo Visual studio code unable to color syntax on python interpreter tomtom 4 6,866 Mar-02-2022, 01:23 AM
Last Post: tomtom
  How to set Tab size to 4 in Python interpreter? zzzhhh 1 1,838 Jan-18-2022, 12:11 PM
Last Post: snippsat
  readline.parse_and_bind() does not work in start-up script of Python interpreter zzzhhh 0 1,521 Jan-18-2022, 11:05 AM
Last Post: zzzhhh
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,203 Sep-09-2021, 01:25 PM
Last Post: Yoriz
Exclamation "System cannot find path specified"(Geany) kiwi99 2 3,862 Mar-18-2021, 07:37 PM
Last Post: kiwi99
  Change icons of system rizzla 1 1,911 Jan-28-2021, 03:30 PM
Last Post: Marbelous
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,615 Jan-11-2021, 06:30 PM
Last Post: ykumar34

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020