Pycharm terminal does not recognize -r command [duplicate] - python

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

Related

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 to run a pip install command from a subproces.run() [duplicate]

This question already has answers here:
Installing python module within code
(12 answers)
Closed 1 year ago.
I see in this article: making and automatic python installer that you can use:
subprocess.run('pip install module_name')
or
subprocess.run('pip install -r requirements.txt')
in this format to install modules either individually or form a file. But when i run this command I get this error:
FileNotFoundError: [Errno 2] No such file or directory:
is there a way to run this like that without having to do this:
subprocess.run(['pip', 'install', 'module_name'])
I suggest you stick to subprocess.run(['pip', 'install', '-r', 'requirements.txt']). To quote the subprocess docs.
Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names).
Avoiding the use of shell=True will save you a lot of trouble if you ever want to run the script on a different system. In general, though, I recommend avoiding reliance on a shell. That is, after all, why you are using Python and not, say, Bash.
To make it work on Linux I used the shell=True parameter. On Windows, it worked perfectly, without it.
subprocess.run("python -m pip install -r requirements.txt", shell=True)
Found the answer here.

Why is the windows cmd not working for me? [duplicate]

This question already has answers here:
"python" not recognized as a command
(14 answers)
Closed 3 years ago.
While on windows cmd I am coding
C:/Users/Esteban Oquendo/Desktop/python myexample.py
Why I am getting an error message as
'python' is not recognized as an internal or external command,
operable program or batch file.
What I am doing wrong?
You have to make sure that the python.exe folder is in your system path.
Make sure python is installed at the location
C:/Users/Esteban Oquendo/Desktop/
So, make sure python.exe file is present in the directory. If you are not sure where your python is installed. Try this is your windows command line:
which python
You will see the python location if you have python in your system (and if the python path is set correctly). Like this!

unexpected character after line continuation character when opening file in command line [duplicate]

This question already has answers here:
syntax error when using command line in python
(7 answers)
Closed 4 years ago.
I have just started learning python and make a python file called "helloworld.py" and store it inside a file called "python py" on the desktop, but this keep poping out whenever I am trying to open it in command line like this:
Can someone tell me what's wrong?
You are in a python shell (we can see that from >>>). Try starting cmd.exe and then run your same command:
python helloworld.py
(from the same path as the helloworld.py file).
When you run Python.exe (as you did), you can not run scripts. This is just for running commands "live". In your shell, try for example print(1). It should work.

Pycharm Command Line Codes [duplicate]

This question already has answers here:
Pycharm and sys.argv arguments
(12 answers)
Closed 5 years ago.
I recently just downloaded PyCharm, and I want to get to know it better, however, codes that I would normally run through the terminal, like an argument parser, I no longer know how to do. Here is an example of what I would put into my command line:
python read_in_data -w wide_data_set -s row_number -o output_path
This would then run the code with my given arguments.
Any basic tips on PyCharm would be helpful, as I am very new to it.
(Top of your screen) Go to Run > Edit Configurations, then enter the command line arguments into the "Script parameters" box. These will then be used when you run the code.
For basic tips/an intro to PyCharm - see the tutorial videos on their website.

Categories