Python version output [duplicate] - python

This question already has answers here:
Which version of Python do I have installed?
(26 answers)
Closed 12 months ago.
Every time I type "python -v" in cmd or another terminal result same
here

You must type the v option uppercase python -V or with --version

According to the --help
-v is verbose mode: It traces all inputs
-V returns version.

Related

Pycharm terminal does not recognize -r command [duplicate]

This question already has an answer here:
pip not recognizing "-r" command
(1 answer)
Closed 5 months ago.
I'm trying to run the command :
pip install -r common\requirements.txt
In the pycharm terminal. However, I get the following error:
ERROR: Invalid requirement :'-r'
When I execute the command above without "-r", pycharm tells me to add it to the command.
Can you please help me identify the issue?
As user defiant wrote, the solution was to replace the "-" character with a manually written one, because when you do copy+paste on this command, it registers the "-" as a different character

Windows: Unable to run a shell script in spyder (python 3.8). Invalid Syntax error [duplicate]

This question already has answers here:
How to run .sh on Windows Command Prompt?
(11 answers)
Why does "pip install" inside Python raise a SyntaxError?
(7 answers)
Closed 10 months ago.
I am trying to run a shell script in Spyder (Python 3.8).
I have tried the following and all this is giving me the same error - Invalid Syntax
bash ./filename.sh
bash filename.sh
sh filename.sh
sh ./filename.sh
shell ./filename.sh
shell filename.sh
import subprocess
subprocess.run(.\filename.sh)
source filename.sh
9.
import subprocess
subprocess.run(filename.sh)
The last one gives the error:
name 'filename' doesn't exist.
Note: I have rechecked my pwd.
Add quotes
subprocess.run("filename.sh")
Also, I would like to point out that unless you are using some package to add the syntax bash, sh, etc... you would get the syntax error since Python doesn't know what those keywords mean.

How can I run inline Python code in a command-line shell? [duplicate]

This question already has answers here:
How to execute Python inline from a bash shell
(4 answers)
Closed 2 years ago.
In a shell, I can execute AppleScript command-line code like so:
osascript -e "tell application \"Finder\" to activate"
Is the same thing possible in Python, e.g.:
python --execute "print('hello world!')"
Something like this should work for you!
python -c 'print("Hi")'
Probably a duplicate of How to execute Python inline from a bash shell

How to make `python2 -V >> myfile` "work"? [duplicate]

This question already has answers here:
Redirect all output to file using Bash on Linux? [duplicate]
(6 answers)
Closed 6 years ago.
I want to automatically record my python version in a computerinfo file. However
python2 -V >> myfile
prints only to the console but not to myfile. How can I get the output into a file?
Curiously, for python3 -- python3 -V >> myfile -- this works as I expected.
I am on Ubuntu 16.04 and I use the bash shell.
There is a bug in python2 -V, that prints the version as stderr instead of stdout. Try to redirect the stderr like:
python2 -V 2>> myfile

Store the output of command in variable in unix [duplicate]

This question already has answers here:
How to store standard error in a variable
(20 answers)
Closed 7 years ago.
Need to check the version of python so for that i am hitting this command in a script.
I am trying to store the output of the given command in a variable "x".So that I can use this x in further script.
But when I am trying to print x it is showing null value(no value).
[bin]$x=`/path/thirdparty/python/2.7/bin/python2.7 -V`
Python 2.7.8
[bin]$echo x
Please help me to store the value of the command in a variable.
python -V writes to the standard error, not to the standard output. So you have to redirect STDERR (2) to STDOUT (1).
$ x=$({python -V} 2>&1)
$ echo $x
Python 2.7.6
Hm... the output is possibly written to stderr, not stdout. Try this:
x=`/path/thirdparty/python/2.7/bin/python2.7 -V 2>&1`

Categories