I just downloaded Sublime Text 3 for Mac and tried to run print("Hello world!") as a test by clicking on "build".
The output says
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't find 'main' module in ''
and some other stuff.
I'm using Python 3 for several months now and I know the main differences between Python 2 and Python 3, but I have no idea what that output means.
Hi I also get the same problem in sublime text 3. And I am fixed.
Open command palette and install the install package.
After completed install python3.
And change like build system, syntax and others.
Finally try to print('hello world')
Save the file in .py extension is must otherwise you getting the same error
Related
I installed SublimeREPL to interact with my python code via Anaconda Package Control.
NameError: name 'tony' is not defined
I noticed that I am getting a NameError on a simple input function.
The error is caused by the python version difference between SublimeREPL(python v2) and my Sublime Python Built Systems version(v3).
I followed this post to upgrade SublimeREPL to version 3, however, you can not edit Main.Sublime-Menu. Please advise on best steps to take in order to update SublimeREPL to Python v3.
def greetings():
name_input = input('please enter your name:' )
print('hello {}, please enter your age: '.format(name_input))
greetings()
Sublime Text 3 Image
On macOS, the file you want to edit is located at ~/Library/Application Support/Sublime Text 3/Packages/SublimeREPL/config/Python/Main.sublime-menu. Open it up in Sublime as a JSON file. Go to line 53 and change python to python3, optionally with a path preceding it if you know exactly where it's stored. For example, if you're using Homebrew, it might be in /usr/local/bin/python3. The line should now look something like this:
"cmd": ["python3", "-u", "$file_basename"],
or this
"cmd": ["/opt/local/bin/python3", "-u", "$file_basename"],
(this is the MacPorts location).
Save the file, and the menu option should now work.
great question and answer. note; you can use f-strings , improved string formatting syntax on your code, see below.
def get_user_input():
name_input = input('please enter your name:' )
print(f'hello {name_input}, please enter your age: ')
get_user_input()
I've been trying to follow online youTube videos to install kivy on my Windows 10 computer (python-3.7.5-amd64, kivy 1.11.1). Aside from the fact that they seem to have different variations on how they approach the topic, I am unable to get a solution that operates satisfactorily.
These are the steps I am following:
I install python (python-3.7.5-amd64.exe) to C:\Python37
I modify the path to include to include the following: C:\Python37\Scripts;C:\Python37;C:\Python37\Libs;C:\Python37\DLLs;C:\Python37\Lib\site-packages;
I added the following environment variable PYTHONPATH = C:\Python37\DLLs;C:\Python37\Libs;C:\Python37;C:\Python37\Scripts;C:\Python37\Lib\site-packages;
I open a command window and type in the following commands (taken from kivy.org)
python -m pip install --upgrade pip wheel setuptools virtualenv
python -m pip install docutils pygments pypiwin32 kivy_deps.sdl2==0.1.* kivy_deps.glew==0.1.*
python -m pip install kivy_deps.gstreamer==0.1.*
python -m pip install kivy_deps.angle==0.1.*
python -m pip install kivy==1.11.1
python -m pip install kivy_examples==1.11.1
I try to run a simple program. From within Windows Explorer I right click the code file (label.py) and from the shortcut menu select python.
A windows pops up for an instant and a directory called __pycache__ gets created with kivy.cpython-37.pyc. Double clicking that causes the program to run.
Is it possible to have a easier solution in which the source code, once compiled executes?
If I open a command prompt and attempt to execute the source code using the command python label.py I get the following:
Traceback (most recent call last):
File "label.py", line 1, in <module>
from kivy.app import App
File "C:\Users\chrib\Google Drive\_Software\Python_Kivy\kivy.py", line 1, in <module>
from kivy.base import runTouchApp
ModuleNotFoundError: No module named 'kivy.base'; 'kivy' is not a package
Why should this happen?
Also is it possible to have a cleaner development environment. I am used to Visual Studio IDE and it would be great if I can use this environment.
Thanks
Code for label.py
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello world!');
if __name__=='__main__':
MyApp().run();
I've been trying to follow online youTube videos to install kivy on my Windows 10 computer
Have you tried simply following the instructions on kivy.org? There's no need to use youtube videos, the installation is largely a normal python module install.
I try to run a simple program. From within Windows Explorer I right click the code file (label.py) and from the shortcut menu select python.
Don't do this, run the file by opening a command prompt and typing python yourfilename.py. That way you will see the full traceback for any errors that occur.
A windows pops up for an instant and a directory called pycache gets created with kivy.cpython-37.pyc. Double clicking that causes the program to run.
It sounds likely that the first run is crashing. As above, you want to get the information about why.
Is it possible to have a easier solution in which the source code, once compiled executes?
When you run the code it does execute. As above, it's probably crashing.
ModuleNotFoundError: No module named 'kivy.base'; 'kivy' is not a package
Have you made a file named kivy.py? It looks likely that you have, and that this file is being imported in preference to the installed kivy module.
Also is it possible to have a cleaner development environment. I am used to Visual Studio IDE and it would be great if I can use this environment.
I'm not sure what you consider unclean about your development environment, but you should think in terms of python environments and their installed packages. Kivy is just a python module that you install into a python environment. When you use an IDE, it may integrate with one or more python environments (with options to switch between them). There's nothing special about using Visual Studio with Kivy, just do whatever you normally do to use it with Python.
I figured it out. I had a program in the code directory called kivy.py. I renamed that and it worked.
I am trying to import Python modules (e.g. pandas or openpyxl) into Sublime Text 3.
I installed the modules on the command line using pip3 install. If I try to import the modules into the command line, they work. For instance,
import openpyxl
will run.
However, when I try the same on Sublime Text 3, I get the following error:
ModuleNotFoundError: No module named 'openpyxl'
How do I import those modules into Sublime Text 3?
It has been over a year since I asked this question myself. A few classes later into Command Line and Python I know 'somewhat' better what I am doing, and now came back to share the answer to this:
The problem here is that the versions of python that Sublime are using are not the same ones that my Command Line or my Jupyter Notebook are using. These 2 are using anaconda3/bin/python3. So the solution to this problem is to have Sublime use a Build that is pointing to this python (where the modules like openpyxl are installed).
On Sublime Text > Tools > Build System > New Build System...
Use this:
{
"cmd": ["path_to_your_desired_python_version", "-u", "$file"],
"file_regex": "^[ ]*File \"(…*?)\", line ([0–9]*)",
"selector": "source.python"
}
and change "path_to_your_desired_python_version" to point to your desired version of python.
Now save the build you just created, for example "Python3.7X.sublime-build".
From now on, you can select that build in Tool > Build Systems.
In my case, after creating a new build system, command+B can successfully import pygame, but F5 run still reported an error.
I checked the user file of the modified F5 hotkey in the ST and found that the BUILD path in it also needs to be changed, so it is solved by changing to the same python path as the newly created .sublime-build file.
I too had same problem. Couldn't import requests, pandas and some of other modules in sublime. I went to command prompt 'cmd', and first checked python version. If it shows you the version, that means python was installed correctly. Then i ran the command 'pip install requests'. This installed the requests module, and so i installed other ones as well. It's working fine since then on sublime.
Where am I going wrong about with Pygame in PyCharm??
1 I have installed Pycharm and its works
2 I have installed Python and Pygame. I have ran "python -m pygame.examples.aliens" in the cmd and the game loads.
3 I have anaconda3 on my computer and that works i.e. you can use the files in the library
4 When I go to Pycharm and type "import pygame" I get an error line
5 So I try and change the interpreter to where Pygame is located and it does not work.
How do you get Pygame into an interpreter. Or what the hell am I missing.
The package will be available only for the version you've installed, python2 or python3.
It looks like you installed pygame into python2, if this command works in cmd:
python -m pygame.examples.aliens
To check or change the default interpreter used in PyCharm:
-menu File > Build, Execution, Deployment > Console >
Python Console > Python Interpreter
By modifying this you don't change the interpreter in your current projects, you can create a new project to check if Pygame is working now.
In your current projects, you can see what interpreter is enabled, in the top right corner toolbar:
-name of the file > Edit configurations > Python interpreter
Maybe you can install Pygame in Python3 to avoid the issue
I am running python 3.3.5. I can't figure out how to launch the IDLE IDE. I installed everything correctly but the IDLE doesn't appear anywhere.
To start it from the command line in Python 3.3+:
$ python3 -midlelib
Or in the code:
import idlelib.PyShell
idlelib.PyShell.main()
You will find an idle.py file at C:\Python33\Lib\idlelib.
There are 2 idle.pys file and both of them work. The first opens a command prompt alongside idle and the other doesn't.