I have a python file located at myFile.py that works perfectly fine when I run it from visual studio code or any python file launcher.
The problem is that whenever I run it using the python myFile.py command in the windows command prompt it just opens the Python Modify Setup (image below) instead of running the file.
Repairing or modifying python isn't the solution.
Here's a video showing the problem.
This problem is due to the python installation file python.exe being in the same directory as myFile.exe. It should be removed from that working directory.
Related
I am running Cygwin terminal in Visual Studio Code (2019), and I tried to run hello.sh and hello.py file, but nothing gets printed out in the terminal. No error message either. I also tried to open a Cygwin terminal outside of Visual Studio, nothing gets printed out either.
However, I created the same files from Pycharm in a venv directory, and copied the files into my Cygwin directory -- it worked.
code in hello.py file:
print("hello world")
code in hello.sh file:
echo hello world
I run these files with the same commands in all of the aforementioned terminals:
./hello.sh
python hello.py
Output when I use hello.py and hello.sh files generated and copied from Pycharm:
hello world
Otherwise nothing goes on when run these two files from Cygwin.
I wonder how this happened and how to generate .py files and .sh that will work directly in VS Studio.
I have seen other threads mentioning a "command not found" error when running .sh files. It is not my case, since no error gets printed out.
Thanks!
According to your description, I tested this process on my computer, and it is recommended that you could refer to the following:
Please ensure that the download and installation of "Cygwin Terminal" is correct.
Before using this terminal to execute a file, please go to the parent folder where the file is located.
1). Execute the "hello.sh" file in the "Cygwin" terminal outside of VSCode:
2). Use the "Cygwin" terminal to execute the "hello.sh" file in VSCode:
3). Use the "Cygwin" terminal in VSCode to execute the "hello.py" file:
In addition, in order to use the "Cygwin" terminal in VSCode, I used the following settings in "settings.json":
"terminal.integrated.shell.windows": "...:/cygwin64/bin/bash.exe",
I think I am close to solving my issues but need a little help.
Computer: Mac
My situation: wrote a script in Jupyter Notebooks (.ipynb) and I wanted to run it from IDLE. So I downloaded the .ipynb as a .py file. When I open up the file it opens in Idle and when I go to run the file it says I do not have the module/packages installed.
At the top of the .py file it put #!/usr/bin/env python
When I run which python in my terminal I get /opt/anaconda3/bin/python.
So I am thinking IDLE is running the script through a different environment of python. How do I change it so IDLE will run the script through the python Anaconda also uses?
Thank you!
It is possible that you have more than one python in your OS. Just check the versions in prompt with --version. If you get different python version you need to delete one that you dont use. It is generally the other than anaconda one.
Wrote a game and compiled it with pyinstaller. An EXE file was created but when I go to run it, it thinks for 3-4 seconds and then it returns to command prompt.
Clicking from the folder in Windows does nothing.
No errors, nothing! Do I need something in my code to allow this to run? The only imports are tkinter and random.
Edit 1: tested a "hello world" script to see if there were issues with pyinstaller, it ran fine.
I understand that the post is older, but it may be useful for other member who may come across the similar problem.
I had created a script using Jupiter notebook and it creates ipynb file.
When I create an exe file using pyinstaller, the exe was doing nothing.
I resolved it by first converting ipynb file to py file using below command:
pyinstaller my_script.py
It will create the py file under same location.
Now, execute below command to create exe file:
pyinstaller my_script.py
It will create exe file under dist folder.
And it works.
I wrote a script on my Windows machine using python 3.6.0. I wanted to run it on Linux machines as well so I transferred the .py script onto my Ubuntu VM. The problem is, I tried to install python 3.6.0 in every way possible but it doesn't really work. Python3 works when I want to execute a .py file, but since I am trying to use pyisntaller to convert it into an executable for linux, I need the default version as 3.6.0. python --version gives me Python 2.7.2. How can I fix this so when I do python --version it shows 3.6.0?
There is no point in changing your default python version, Ubuntu relies heavily on older versions of python. And what do you mean by convert it into an executable for Linux? Almost every file on your file system is an executable. If you want to make your program run as a command in the terminal you can do this though:
text_editor_of_your_choice .bashrc
This should open the hidden .bashrc file, and scroll to the bottom of it. Below is what the file looks like...
.bashrc
After that you can create a function for the python command you want to run.
eg. function ghst {python3.6 /home/user/example_script/example.py $#}
Start a terminal session and then try running it. Now that's if you want to run it inside the terminal. If it you want to create this "executable file" you speak of you can create a simple shell script.
First go in the terminal and run touch file_name_of_your_choice.sh
This will create a blank file named file_name_of_your_choice with the file extension "sh". After that open the text file in whatever directory you created it in, if you are unsure do pwd.
In your first line make sure that the user is inside the directory of the .py file by doing
cd /home/user/folder/ On the next line you should then execute the .py file. You can do this by typing this: python3 file.py. This will execute the program inside a terminal window. After you have done all of this make sure that the python file and the script file are executable. Do this by doing chmod +x file.py and chmod file.sh.
This is what the end result looks like
example script
You mentioned inside your question that you want your program to be able to run on Linux machines as well. Whether this is for personal or a public project of some sort it comes in handy by packaging all the required files in a .zip format this makes it easy to unpack everything when moving to separate machines. If there are any problems let me know.
I want to create a .bat file to run my .py file on Windows without Python installed, mainly so I can send my programs to friends. So in my .bat file I would like to:
Change to the current working directory. (So it runs wherever the file is)
Change directory to a folder inside that directory.
Run a python file without my friends having to install python themselves.
Run a .py file without Python installed using .bat
You can't run a Python script using a batch command without Python being installed. You can compile an executable with Py2exe (which bundles an entire Python interpreter with your script), or convert a subset of Python to C++ with shedskin, which can then be compiled to an executable. You could also issue a shell command to install Python if it's not already installed and the user has internet.
But doing exactly what you asked is impossible.
Take a look at http://www.py2exe.org/ which will convert you python code to a executable windows program that you can send to your friends.