Hi I got the project on the github, I want to analyze this code using debugging.
The project uses python 3.6 and requires next command when running
python -m pixloc.run_Aachen
pixloc is package (directory) name and run_Aachen is python file name.
When I run this command using Pycharm, It is successful
but When I run this using Pycharm Debug mode, It is fail
the following image is my Run/Debug Configuration
enter image description here
What can I do for this problem
I try to use setuptools.setup(), but this isn't work
I just want to use -m option in debug
Your run configuration is currently set to to run a Python script (i.e., as python ./path/to/script.py), but you want to execute a module (i.e., python -m package.subpack.mod).
To change your run configuration to one that executes a module, do the following:
Under the run configuration, click on the first dropdown that reads "Script path" and change it to "Module name".
Then, specify pixloc.run_Aachen in accompanying testbox.
Related
I have a MacBook air and have tried opening Python in terminal but when I open it, it opens Python interactive mode. Does anyone know how to open Python script mode please.
I’ve tried typing in things such as Python or Python 3 like safari suggests but that didn’t work.
There is no 'script mode'. You can create a Python script using TextEdit or another editor, save it as myfile.py, and then run it with python myfile.py.
for running what you are calling 'script version' of python you should choose a python file to run and make sure is written in the same or in a compatible version to the python you are running it with (python2, python3)
For running an example script:
python main.py
You need to be in the directory containing the file so make sure you are there before running the command. Using python runs the first version of python you installed, so if you want to use an other you should use:
python2 main.py
python3 main.py
etc
Assuming you've stored your script in a file named itworks.py, the simplest thing is to type the command python3 itworks.py in a terminal window after you've moved to the directory containing the script. Alternatively, you can type python3 followed by a space, then locate your python script in the Finder and drag and drop it into the terminal. This will expand to the full path to the file, allowing you to run a script located elsewhere than your current directory. Don't forget to press return...
In older versions of MacOS you could say python, but that uses python 2 which is no longer supported so you should go with python3 for any new development. (With MacOS Ventura, python 2 seems to have been removed.)
If you have multiple versions of python, you can use the command which -a python3 (or python) to see all versions on your PATH, and the order in which they will be found. PATH works on a first-come-first-served basis, but you can override by using the fully qualified path name to an alternative python.
Yet another solution, for when you want a more permanent script you will use many times in the future, is to use a "shebang" line as the first line of your script. For example, I wrote the following tiny demo:
#!/usr/bin/env python3
print('It works!')
The first line says to parse this script with the first python3 interpreter found in your current environment's PATH. You could replace that with an explicit path such as #!/opt/homebrew/bin/python3. Now make the script executable: chmod a+x itworks.py. You can now run the script from the current directory by typing ./itworks.py. (The leading ./ tells your shell you know it's in the current directory, and is intended as protection against trojan horse scripts.) If you want to be able to use the now-executable script from anywhere, add it to a directory on your path such as /usr/local/bin, and you'll be able to run it by just typing itworks.py.
I installed VSCode, downloaded official Python 3.6.4.
VSCode detected and set the environment right - I do see "python.pythonPath" user setting set correctly.
But, when using VS Code using Ctrl+F5to run a Python file, I am always getting asked for "select environment" and it shows me two options
- Python
- Python Experimental
What is this "Python Experimental"? How can I get rid of getting interrupted every time I try to run a script?
Run > Add Configuration... => Choose one of the two options.
After doing this it will no longer prompt you.
Ctrl+F5 is a shortcut to Start without Debugging What you want is just running a file according to your post. To run a python file in the integrated terminal, right-click your editor window and Run Python File in Terminal. It should open up a terminal window within VS Code and run as normal. It also takes into account the environment you are currently using whenever you run it.
To answer your other question about Python Experimental, it is an option to use the experimental debugger, an alternate version of a Python Debugger. You can read the instructions here
My python entrypoint needs to be run as a module (not a script), as in:
python -m foo.bar
The following does not work (and is not supposed to):
python foo/bar.py
How can I create a run confirguration in pycharm that runs my code using the first invokation above?
In 2018.1 it is finally possible to specify the module name instead of the script path in the UI. There is a dropdown for changing it, to the left of the input field.
There is a workaround I use for my scripts, which do use relative imports.
python -m actually invokes a script called runpy.py which is part of a standard Python installation. These two invocations are equivalent:
python -m my_module.a.b module_arguments
python python_lib_directory/runpy.py my_module.a.b module_arguments
Use the latter method to setup your Run/Debug Configuration:
Script: python_lib_directory/runpy.py
Script parameters: my_module.a.b module_arguments
Interpreter options: (leave blank, no -m required)
According to man python, the -m option
-m module-name
Searches sys.path for the named module and runs the corresponding .py file as a script.
So most of the time you can just right-click on bar.py in the Project tool window and select Run bar.
If you really need to use the -m option, then specify it as an Interpreter option, with the module name as the Script in the Edit Configurations dialog:
IntelliJ IDEA / PyCharm 2017
Field "Script" is optional in the recent versions of JetBrains IDEs. Specifying -m foo.bar in "Script parameters" is enough:
In PyCharm 2016 specifying -m without a script path doesn't work, as they use a wrapper script that doesn't accept the -m argument.
Here's my solution, which works for run & debug configurations: https://github.com/amnong/misc/tree/master/pycharm_runner
Edit: I just read J. R. Petrus's comment, and my solution is very similar. BTW I also tried to support proper entry points using pkg_resources, but for some reason pkg_resources.load_entry_point() could not find my project's distribution...
I want to use behave lib in my program. I write code as in behave-tutorial.
But, when I "Run" my tutorial-project, I see in PyCharm-console:
C:\Python27\virtualenv\Scripts\python.exe "C:/Program Files (x86)/JetBrains/PyCharmProjects/tutorial/steps/tutorial.py"
Process finished with exit code 0
I think what I must to use behave.exe for run my project:
C:\Python27\virtualenv\Scripts\behave.exe
How to get it?
You can configure your run as per your purpose please have a look to screenhots here:
taken from: http://automated-testing.info/t/bdd-framework-debug-testov-stepov/3392/3
Even though behave support is now in the Professional Edition, it's currently not in the Community Edition.
You can still call the behave module for a given feature directory.
Add a Python Run configuration, with no script and these options:
Interpreter options: -m behave
Working directory: path/to/feature/directory
I tinkered around with previous answers and got PyCharm CE 5.x working with Behave I have python 2.7 installed system-wide, and behave installed via PyCharm package management
Here is my run config:
Script: put dot (.) in here [this way PyCharm recognizes the configuration as valid and doesn't show red cross mark]
Working Directory points to the dirctory where .feature file is
Interpreter options: -m behave
For PyCharm Community 2016.3 on mac, setup a run configuration with:
Script: /usr/local/bin/behave
Script Parameters: path/to/feature/directory
Working Directory: path/to/project/directory
This way the run & DEBUG both work.
I have 2 features file (createX.feature and createY.feature) at feature directory but I want to select only 1
My configuration is
Script: createY.feature
Script parameters: --tags=#int --tags=#e2e
Interpreter options: -m behave
Working directory: $features_directory
The "Run" window shows this execution command
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 -m behave createY.feature --tags=#int --tags=#e2e
but pycharm chooses the other feature file :(
But if I run the command at a terminal window, the command works!!
Edit: I have changed the feature file I want to execute for a better understanding: I try to execute the last one following alphabetical order
Edit 2: Solved It seems that behave does not like to have "scratch" files for control tasks at steps directory ... Once I deleted them, that handsome configuration works!!
How do I run a Python file from the Windows Command Line (cmd.exe) so that I won't have to re-enter the code each time?
Wouldn't you simply save your Python code into a file, and then execute that file using Python?
Save your code into a file called Test.py.
And then run it?
$ C:\Python24\Python.exe C:\Temp\Test.py
If you don't want to install an IDE, you can also use IDLE which includes a Python editor and a console to test things out, this is part of the standard installation.
If you installed the python.org version, you will see an IDLE (Python GUI) in your start menu. I would recommend adding it to your Quick Launch or your desktop - whatever you are most familiar with. Then right-click on the shortcut you have created and change the "Start in" directory to your project directory or a place you can mess with, not the installation directory which is the default place and probably a bad idea.
When you double-click the shortcut it will launch IDLE, a console in which you can type in Python command and have history, completion, colours and so on. You can also start an editor to create a program file (like mentioned in the other posts). There is even a debugger.
If you saved your application in "test.py", you can start it from the editor itself. Or from the console with execfile("test.py"), import test (if that is a module), or finally from the debugger.
If you put the Python executable (python.exe) on your path, you can invoke your script using python script.py where script.py is the Python file that you want to execute.
Open a command prompt, by pressing Win+R and writing cmd in that , navigate to the script directory , and write : python script.py
A good tool to have is the IPython shell. Not only can it run your program (%run command), but it offers also many tools for using Python interactively in an efficient manner (automatic completion, syntax coloring, quick access to the documentation, good interaction with Matplotlib,…). After you install it, you'll have access to its shell in the Start menu.
You need to create environment variables. Follow the instructions here: http://www.voidspace.org.uk/python/articles/command_line.shtml#environment-variables
In DOS you can use edit to create/modify text files, then execute them by typing python [yourfile]