run setenv linux command in python script [duplicate] - python

This question already has answers here:
How to set environment variables in Python?
(19 answers)
Running 'export' command with Pythons 'subprocess' does not work
(1 answer)
Closed 2 years ago.
I want to run setenv command through python script, the linux command is as below
setenv MODEL path/to/the/model
I tried using os.environ(), but I couldn't get the right syntax.
note - I'm using python 2.7

os.environ isn't a function. Check out the docs: https://docs.python.org/2/library/os.html#os.environ
This question may also be helpful to you: How to set environment variables in Python. If it is, pay attention to the comments on the top answer.

Related

execute a python package from the shell step by step e.g. debugging mode [duplicate]

This question already has answers here:
How to step through Python code to help debug issues?
(15 answers)
Closed 2 years ago.
I want to observe the data flow in a package that is executed in the shell. Is the freqtrade bot. I want to run it step by step so I can observe the dataflow. This have to be executed in the shell with some parameters e.g.:
"freqtrade trade -s strategy"
How could I do this from the shell or from vscode allowing me to go through each step, like if it was debugging mode (which I could not do for the package either)?
there is a debugger called pdb. Check here

Opening Python code with a specific version [duplicate]

This question already has answers here:
Multiple Python versions on the same machine?
(11 answers)
Closed 3 years ago.
while there are multiple versions of Python installed on a Linux machine, is there a way to mention in the script to be open with a specific version, say, 3.8 even if we issue the #python script.py as opposed to python3.8 script.py ?
I don't want to use Linux alias command. I wanna know if that is possible to be accomplished within the script
Use shebang. #!/usr/bin/python
In the first line of the code with the serial number of Python you want at the end.
You'll need to then run your script like ./my_script.py
You can select the interpreter by adding
#!/usr/bin/env pythonXX
as the first line in your script, provided the version is in the path.
You can also invoke the interpreter directly with the script as the argument.
pythonXX script.py
Depending on your situation
pythonXX -E script.py
might be better. That way the interpreter ignores paths set by environmental variables.
For more details view
https://docs.python.org/3/using/cmdline.html

VS Code - can you display a Python shell [duplicate]

This question already has answers here:
How to execute Python code from within Visual Studio Code
(34 answers)
Closed 4 years ago.
When using Python IDLE I find the Python shell, with the >>> prompt very useful for testing syntax. Is there a way of getting a Python shell integrated in VS Code?
Maybe the answer is just to open Python IDLE in another window.
Apparently this is a duplicate of another question, but I did several searches on the words Python shell and didn't find anything that seemed relevant. Sorry.
Many thanks to Jaxi for the answer that you need to type Python in the Terminal Window.
stated here you can use ctrl+backtick to open a terminal window, then from there just type python and it will give you the python shell:
https://code.visualstudio.com/docs/editor/integrated-terminal

Python3.6 on Windows MINGW64 console doesn't run the interpreter [duplicate]

This question already has answers here:
Python not working in the command line of git bash
(20 answers)
Closed 5 years ago.
I'm experiencing the same issue as this question with Python 3.6. It works well under the Windows console, but it fails to launch or work under MINGW64. Even when I use the direct path of /c/Python36/python.exe, nothing happens. I don't get the interactive REPL with the usual Python interpreter version and >>> prompt, as I do in the Windows console.
Any pointers on how to debug this?
Ah - further search yielded this stackoverflow question that contained the answer - use python -i

Run python-script from CMD - windows [duplicate]

This question already has answers here:
How to execute Python scripts in Windows?
(9 answers)
Closed 6 years ago.
I want to run my python script without the python keyword at the beginning.
Example :
I don't want python script.py.
I want script.py
The problem is that when I run it how I want the script opens in a text editor, and it doesn't run in the console...
Why?
I just had to set the default opening of the file with python.exe,
By default it was with VS Code.

Categories

Resources