Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
It seems to me python -m myscript and python myscript do the same thing: running a script.
What is the purpose of using -m? Thanks.
In some cases, especially for very small projects, python script.py and python -m script will be pretty much the same.
The biggest difference is when your module lives in a package and has relative imports. If you have a script that import something like from .module import some_name, you will most likely get a ModuleNotFoundError when you run it with python package/scripy.py. On the other hand, python -m package.script will produce whatever output you expected.
You can load modules and invoke them as script. The exact file name or path is not needed. Example:
python -mjson.tool myfile.json
This will print a formatted version of myfile.json, and it loads the module json.tool for this. Python searches for this module automatically. You don't need to know the exact path.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Just finished making my first python game based on the space invaders game. Now I don't know exactly how to share it with my friends. I know that I should use py2app, but I haven't found good online instructions on how to do so.
This is how the project file looks like:
I'd appreciate it if someone could help me out.
pip install pyinstaller - this module can generate executables of python scripts.
Then simply run: pyinstaller main.py or whatever the main file is named and it will generate an executable including all needed modules (you can find the
generated package in new created dist folder).
You can try using Py2exe, which, as the name suggests, compiles Python programs to an executable format.
Edit: Just noticed you were using MacOS, here is a Py2app tutorial instead.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Before you get confused, I am going to compile it with the auto-py-to-exe module after, its just the source code is in python. How do I do this?
If Python is not installed you wouldn't even be able to run a script to check if it's installed.
I'm pretty sure there isn't from inside the Python script. Because the interpreter isn't installed, so it'll never be able to understand HOW to execute the script at all.
You'll have to check outside in whatever is initiating the Python script and the compilation (bash script?) and do it there.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm writing a script in Python, but when I attempt to run it a cross cursor appears and lets me take screenshots. But that's not part of my program, and the rest of the script never executes at all!
The minimal code that produces this behavior is:
import fiona
import scipy
It's a known issue which regularly happens to some.
Without a python shebang line the script is treated as a shell script. And line import module is treated as a command to run import application, which is present on your system (part of ImageMagick, I guess) and makes a screenshot saving it to the specified file.
It got solved by adding the shebang:
#!/usr/bin/env python
but I really don't understand why...
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I was wondering the purpose of runpy module in Python and how does it help in day to day development of the Python user community?
Can someone please explain the necessity, usage and advantages of runpy module in python?
The docs say:
The runpy module is used to locate and run Python modules without importing them first. Its main use is to implement the -m command line switch that allows scripts to be located using the Python module namespace rather than the filesystem.
You can run a python module like this:
python -m SimpleHTTPServer 8000
The runpy module enables this functionality. It may not be useful outside of this context.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm using Blender and Python and want to give the .py file to other users to use my script... My script uses external modules (like NumPy) which will rise the errors (like can't find module xxxx).
Not all people can install NumPy (or even Python :D) as many Blender users are just artists.
Another note is that NumPy doesn't work with Blender (I install it in the system's Python, then delete Blender Python so it relies on the system Python).
If you want to distribute your code with external dependencies then you should build a Python egg. The .egg format was created to solve the issue you are dealing with. It is a self-contained release of your code with dependencies and meta-data. Here is some information on how create Python eggs.