This question already has answers here:
How to use argv with Spyder
(4 answers)
Closed 2 years ago.
I'm using spyder for python programing.
I've a file.py and I want to run code like:
--model=RNN --optimizer=SGD
but when I run it in the spyder console it gives this error:
SyntaxError: can't assign to operator
So how can I run this?
In Spyder, if you go into the Run menu, you'll find an option named Configuration per file. On my system, you can get directly to that entry with CTRL+F6 (the shortcut key may be different on other OSs).
Once you select the menu item, you'll get a dialog window with several options. The one you want is about halfway down, named Command line options. You will want to check the box, and put the arguments you showed above into the adjacent text field. Now when you run the file, the code will behave as if those options were passed to it on the command line (it will see them in sys.argv).
Related
This question already has answers here:
How to execute Python scripts in Windows?
(9 answers)
Closed 1 year ago.
I tried to update my PyCharm but it got corrupted so I had to reinstall the program, since doing so I lost my previous settings.
Before, I used to be able to enter a file name into the Terminal (Not Python Console) and the code would run.
E.g I have a file named code.py, I could enter 'code' and it would run and print the statement.
print("Hello World")
But now when I try this, the Terminal returns no print statement output and simply opens up the code.py tab on PyCharm. What settings do I need to change? I have included a screenshot.
Open the terminal and type:
python code.py
i hope you already know how to open a terminal in pycharm so after doing that simply run the command that you want to run your code with, in this case it will be:
python code.py
This question already has answers here:
How to run a Python script portably without specifying its full path
(4 answers)
Closed 3 years ago.
I am looking for a way to run a python script from anywhere.
I have seen this solution but as it is based on Linux I am looking for a way on Windows (10).
Basically what I want to do is, execute a script with a given parameter. Because it could be disturbing for the user, I am using a .pyw-file extension to hide the console.
Things that came to my mind:
a PATH-Variable
PowerShell-Script
Batch-file
Sadly I am not familiar/experienced with neither of those, so I can't really tell if these ideas even provide a way to do that.
Any answer is appreciated.
Edit: I would like to make the command as short as possible for the client so it is not necessary to write a novel to exec one simple task.
Another Edit:
I want the user/client to open its cmd/ps and use a command which executes my python-script, which is not in this directory he is, when opening the cmd. So the script is somewhere on his computer, but shall be executable by command from anywhere.
try to create a "code.bat" file with this command "python script.py" inside your .bat file then add the "code.bat" to your path in your environments anytime you want to run the script just type code in your shell.
This question already has answers here:
How to keep a Python script output window open?
(27 answers)
Closed 3 years ago.
In my Python script, I create a .bat file (many actually), and I run them via
os.startfile(blah)
Everything works like expected, however, those terminals die after finishing. I want to keep them open, so that I can type more commands manually in those opened terminals.
How?
You could try using the cmd command to run the batch file, and then use command line arguments for cmd to modify its behavior. For example:
os.startfile("cmd.exe /k blah.bat")
Documentation of the available command line arguments can be found here:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd
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.
This question already has answers here:
Pygame and cx_freeze: segmentation fault
(5 answers)
Closed last month.
I made a game in python, and then exported it with cx-freeze. For some reason, when I try to double-click on the application it opens a command line for about a second and then closes. However, when I run it myself with just the python IDLE it works fine. What am I missing?
If it helps: I have graphic files in a separate folder called data and I'm using the normal python modules + pygame.
If you application is a GUI, you should freeze it with the "Win32GUI" base, so it doesn't open a command line. Have a look at an example in the docs.
I don't know why it's closing again - maybe it's failed to include something it needs. When you freeze it with the GUI base, any error messages should appear in a message box, which might help you work out what the problem is.