Just to get it out of the way, I'm new at Python and coding in general, but very eager to learn how to do it.
The problem is that I can't run Python scripts through Sublime Text. I'm using Mac OS 10.15.7, and I've downloaded the latest version of Python from the official website and then also with Anaconda.
When I try to run any Python script in Sublime, I get the following message:
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't find '__main__' module in ''
[Finished in 0.3s with exit code 1]
[shell_cmd: python -u ""]
[dir: /private/var/folders/wh/lt9wn7qn7zl4p8xkj67bhpyh0000gn/T/AppTranslocation/86FABCDF-E2DC-4C15-A564-EFE9529B919B/d/Sublime Text.app/Contents/MacOS]
[path: /Users/alexherranz/opt/anaconda3/bin:/Users/alexherranz/opt/anaconda3/condabin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
I looked at some other similar questions here, and I installed the SublimeREPL package as many recommended, but I'm probably missing something, as I still get this error message. It's quite frustrating, as I'd like to run the scripts within Sublime instead of copying it everytime to the terminal.
Is there a fix for the problem I'm running in to? Any ideas appreciated!
You've entered code in the editor, but you haven't saved it as a .py file. Save the file, hit ⌘B, and it should run just fine.
Make sure you save the file first, before attempting to run it.
If you "save as" the file somewhere on your computer you should be able to then go into the mac version of the file explorer and then double click your file. If it is a file that opens a window, like tkinter or turtle it will run the code normally. If not it should run the code in the mac version of the command prompt. Make sure it is opening the file with python.
Related
I've been studying Python for a month now and normally I run all my programs in Sublime Text 3.
Today I learn to run Python programs in the terminal window as introduced in this section of the Automate the Boring Stuff with Python book following this video. Basically, I followed the instruction in the video and created the hello.py file as below:
#! python3
print('Hello, World!')
Then I opened the Command Prompt to run the file with the command: py.exe c:\users\danh\mypythonscripts\hello.py,
an error pops-up and states that "This app can't run on your PC" and a line says that Access is denied. I spent the whole day trying to fix this problem but still I couldn't get it running.
One thing is when I change the directory of the Command Prompt to run the file to C:Windows\system32 (or run the Command Prompt as Administrator) and then run the command py.exe c:\users\danh\mypythonscripts\hello.py, it runs the file without any problem as in this image.
Does anyone know how to fix this problem? Any help is appreciated. Thanks!
I solved the problem.
When I looked into my user directory at C:\Users\<Username>, it appears that there is a py.exe file that has 0 bytes.
I was told in this thread that the py.exe file shouldn't be in my user directory so I removed that file and it fixed the problem.
I still don't know how the py.exe file got into my user directory and why it has 0 bytes so I'm not sure this solution could help others. For now, I will accept my own answer because it solves the problem in my case.
It looks like you're trying to use Microsoft's new Windows 10 Metro-based auto-installing version of Python. It's included by default but, as you've found, it doesn't work very well.
Try installing the version from the Python website.
If you've got a 32-bit copy of Windows, make sure to install the 32-bit version; Windows isn't very good at running 64-bit programs from a 32-bit kernel. You can check by looking in your C: drive; if you haven't got a Program Files (x86) folder, install the 32-bit version.
python.exe inside my env\Scripts\ became 0kb for some reason. So I created another virtual-env and copied python.exe from there to this folder. then it started working.
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.
I need to make executable file on OSX/Mac. I have python3 script that uses excel file. Executable file also should be able to work just by double clicking the icon and also have python packages. I mainly work with Ubuntu18 but have access to Mac for few days.
What I've tried so far:
I've written a short bash script that activates python environment (with "source activate" command) and runs python script. Appified the script with this: https://gist.github.com/anmoljagetia/d37da67b9d408b35ac753ce51e420132
I know that terminal commands work but double-clicking the app in Mac does nothing.
With pyinstaller converted bash+python script to exe, then with wine tried converting that to executable program but that double-clicked program does nothing.
Tried py2app, but in the mac terminal it says "cannot execute binary file".
Does someone have any recommendations for my problem? As I've mentioned there are few main requirements:
works by double-clicking
works on mac
has all python packages
is able to read specific excel file (I will know the name of it, but just path may be confusing in some versions, because I would like to use relative path or something like [pwd]/file.xlsx)
Anyway, I'm having most problems with the first two points but don't want to forget the last two.
Thank You for help!
I have encountered an error while try to run a python 3.6.4 script after upgrading from 2.7.
I had initial installed both python 2.7 and 3.6 but them deleted 2.7 because I had no use for it and i am not getting this error.
I have tried:
Reinstalling python 3.6.4
changing the install location of said install
Repairing the python 3.6 install
Error:
A Python script by itself is not an executable program. So if you want to run the script Evosim.py by just entering Evosim.py in the command line, the .py file ending needs to be associated with the Python interpreter. It seems that currently in your system this is not the case.
There are two ways to deal with your situation:
Start your script by entering python Evosim.py instead of only Evosim.py in the command line.
Fix the broken association of the .py file ending with the Python interpreter. The answers to this question migth help you with that.
Solution #1
Go to your registry by searching regedit.
Open category HKEY_CLASSES_ROOT. Select .py. If .py don't exists then make it by yourself.
Double click the Default. It will make a popup. Change its value to Python.IDLE and click OK. Make a new String key in .py naming Content Type with value text/plain.
Solution #2
If the above method don't works then just go ahead and reinstall your python (also uninstall Python Launcher). Your modules and files will be at their place.
You can now open .py files.
Running command prompt as an administrator resolved my issue, and able to execute my python script
1). Right click any python file
2). Click Open with then Choose another app
3). Click on More apps then Look for another app on this PC. It should open up file explorer
4). Select python.exe wherever it is located.
A sample path is C:\Users\<user>\AppData\Local\Programs\Python\Python38\python.exe for a user installation. A way to check this path is by typing where python into cmd; it will list all installations of Python.
Now the python.exe you chose is associated with all .py files and typing file.py should not give an error.
I am very very new to Python. I am trying to get a python program to run by writing 'python hello.py' but every time I do that I get a Syntax Error. Why is that?
However when I open the file and click on run module, it works. Why won't it work if I type 'python hello.py'
Is there anyway I can navigate to the directory where the file is stored and then run it? I tried placing my file in directly in the Python23 folder :P didnt work anyway
Please help me. I have Python 2.3.5
I'm guessing that you're running python hello.py within the Python REPL. This won't work; python hello.py is something that starts Python that you'll need to run in your system shell.
What is the error?
Place python's filepath to the python.exe in your system's PATH, then you can run a python file from anywhere.