Python Forum

Full Version: Python script dioesn`t run all commands
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello I have a Linux machine that has python 2.6 when you log in and with this command scl enable rh-python36 bash I can change it to python 3.6.
I created a script that will run from crontab and it is like this:
import os

os.system("scl enable rh-python36 bash")
os.system("python launch.py")
The ideea is that after I launch this script that I wrote above it just changes the python version but it doesnt launches launch.py
Do you have any ideeas how I can make it work ?

Thanks
python 2.6 is very old. Nothing older than 3.0 will be supported after Jan 1, 2020
see: https://pythonclock.org/
Yes but how can I solve my problem to run both commands and work ?
(Sep-25-2019, 11:37 AM)exploit123 Wrote: [ -> ]Yes but how can I solve my problem to run both commands and work ?

You should use built-in help in your Python 2.6. Python website has currently only 2.7.16 version documentation from 2.XX generation. You know, usual drill: help(os.system). However, I believe that there is not much useful information.

Also along Larz60+ lines, this is excerpt of current os.system documentation (version 3.7):

Quote:The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the Replacing Older Functions with the subprocess Module section in the subprocess documentation for some helpful recipes.

I have no idea whether subprocess is available in 2.6
Give direct Path to python version you want to use.
Try to chaining environment with system/subprocces to 3.6,then try to run make not work.
Example if i want to run a file with 3.8,have 3.7 as default now,can also switch system wide easy as i always use pyenv.
import subprocess

subprocess.call(["/home/tom/.pyenv/versions/3.8-dev/bin/python", "hello.py"])
As mention do not use os.system(),subprocess was new in Python 2.4.