No module named kivy.app - python-2.7

So I thought I'd toy around and try and learn Kivy, as it looks interesting. I have just started trying to get one of their examples working:
from kivy.app import App
from kivy.uix.widget import Widget
class MyPaintWidget(Widget):
pass
class MyPaintApp(App):
def build(self):
return MyPaintWidget()
if __name__ == '__main__':
MyPaintApp().run()
I get the following error:
C:\Kivy-1.8.0-py2.7-win32>python paint.py
Traceback (most recent call last):
File "paint.py", line 1, in <module>
from kivy.app import App
ImportError: No module named kivy.app
I have installed the latest version of Kivy. I see "app.py in the C:\Kivy-1.8.0-py2.7-win32\kivy\kivy folder.
Also, here is my PYTHONPATH:
>>> import sys
>>> for n in sys.path:
... print n
...
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\setuptools-2.0.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\pywin32-218-py2.7-win32.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\plyer-1.1.2-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\kivy_garden-0.1.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\requests-2.2.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\python27.zip
C:\Kivy-1.8.0-py2.7-win32\Python27\DLLs
C:\Kivy-1.8.0-py2.7-win32\Python27\lib
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\plat-win
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\lib-tk
C:\Kivy-1.8.0-py2.7-win32\Python27
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages
Any help would be greatly appreciated. Thank you.

I ran into this error message when I named the script kivy.py, because python looks first in the current directory to fill the dependency, so it never sees the real kivy package.
Renaming the script fixed it for me.

The name of the folder or file cannot be kivy or kivy.py. You need to rename it to another name and it will run ok.

So, I figured it out....I was not being very smart. I'm new to Kivy and I'll answer this for anyone else that is as green as I am. You can't just run this as a python program, doh.
Follow instructions [here] (http://kivy.org/docs/installation/installation-windows.html#start-a-kivy-application) and all will be right with the world.

If you installed kivy using pip you need to add the packages to your environment. In Windows Command Prompt do
pip show kivy
~Take note of the Location of the module.
Next you can do 1 of two things.
Configure any python files you write to refer to the location of your module with sys, use this tutorial for more info: https://kivy.org/docs/guide/environment.html
Add the location you found above to your PATH (Windows): https://www.computerhope.com/issues/ch000549.htm
2 Worked for me.

I was also facing the same issue while running sample app.
I followed simple steps given in : https://kivy.org/doc/stable/gettingstarted/installation.html#install-pip
It worked for me.
Create the virtual environment
Activate the virtual environment.
Install Kivy
run your .py file

I know I am too late but I hope this will help others, I just did not run it from the command prompt, I opened the python code in my python shell and then pressed run 'F5' and it worked for me.

If you're using a virtual environment (venv), make sure you're targetting the the correct Python interpreter. See here for how to to change to the venv interpreter in IntelliJ

Related

ModuleNotFoundError: No module named 'textencoder' error when upgraded to python 3

Currently I have migrated my python2 django project to python 3 & after conversion to py3 I am getting below kind of error for below code.
from hubarcode.code128 import Code128Encoder
encoder = Code128Encoder(pur_num, {'is_reliable': False})
Trackeback is as below.
from hubarcode.code128 import Code128Encoder
File "D:\my_project\venv\lib\site-packages\hubarcode\code128__init__.py", line 16, in
from textencoder import TextEncoder
ModuleNotFoundError: No module named 'textencoder'
I have tried to search for solution online on google but not able to solve it.
Any suggestions ?
Thanks.
I am able to solve issue by using pyStrich.
First you need to install pyStrich using pip3 install pyStrich and after thatn
What you need to do is just replace from hubarcode.code128 import Code128Encoder with
from pystrich.code128 import Code128Encoder.
I hope it may help others who have been facing same kind of problem.
pip freeze will show it if you have this module installed in your venv
pip install textencoder to resolve problem

ImportError: No module named vaderSentiment

I'm trying to run a code in python2.7 on windows os that uses sentiment analysis
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
and I'm getting this error
ImportError: No module named vaderSentiment
Can anyone help me with this?
Assuming you solved this one as it's from 7 months ago, but for anyone else searching for it:
Go into terminal/cmd and paste the following:
pip install vaderSentiment
More info on VADER: https://github.com/cjhutto/vaderSentiment
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
#note: depending on how you installed (e.g., using source code download versus pip install), you may need to import like this:
#from vaderSentiment import SentimentIntensityAnalyzer
read the comment in a code
Try running your file with Python3 instead of just python. Sometimes when you have different pips/pythons installed on your computer you might have vaderSentiment installed in python2 when you need to run it in python3.

How to properly install pygame module in windows? And make games

I have written codes but it's showing cannot import pygame module
Download pygame from here: http://www.pygame.org/download.shtml
If you are not sure which version of python you are running, execute the following code in your shell:
import sysconfig
version = sysconfig.get_python_version()
print(version) #Python3
print version #Python2
Usually, Python3 will also accept the print command without brackets, so using sysconfig is the safest way. Sysconfig will also tell you which minor version you are using (such as 3.4.5)
Once you have download pygame, tryimport pygame in your shell. If this does not work, type help('modules'). This will now list all your modules. If pygame is not in there, check in which folder all other modules are saved and move the pygame module to that file path.
You can also use sysconfig to display all the file paths python is using:
import sysconfig
paths = sysconfig.get_paths()
print(paths) #For Python2, see print method above
I don't quite understand what you mean with "And make games", but the pygame website has a great documentary and some example codes to help you learn progamming with the pygame module.
Hope I could help,
Narusan

No module named os.path : wrong Python being called by bash

OS: CentOS 6.6
Python 2.7
So, I've (re)installed Canopy after it suddenly stopped working after an abrupt shutdown. It worked fine immediately after the install (I installed as my default Python). But after one reboot, when I try to open it with /root/Canopy/canopy (the icon under applications no longer works, either), I get the following error:
(Canopy 64bit) [xxuser#xxlinux ~]$ /root/Canopy/canopy Traceback (most recent call last): File "/home/xxuser/qiime_software/sphinx-1.0.4-release/lib/python2.7/site-packages/site.py", line 73, in <module>
__boot() File "/home/xxuser/qiime_software/sphinx-1.0.4-release/lib/python2.7/site-packages/site.py", line 2, in __boot
import sys, imp, os, os.path ImportError: No module named path
I found this link: Python - os.path doesn't exist: AttributeError: 'module' object has no attribute 'path', but both of my os.py and os.pyc were 250 and 700 bytes, respectively. There was another file called site.py which was 0 bytes and site.pyc was about 100 bytes. What are these files? And would deleting them hurt anything (which is what they did)? And why is this happening after reboot? (using reboot command).
I also found this: https://groups.google.com/forum/#!topic/spyderlib/hKB15JYyLqM , which could be relevant. I've updated my python path before with sys.path.append('/..')
My guess is that for some reason os.path isn't in sys.path? and __boot can't find it? But I'm new to Python and Linux and want to know what I'm doing before I go modifying any boot files, paths, etc.
Thanks in advance.
More information (saw that I'm supposed to update new info in an edit to original question. New to this.)
From one of the comments:
This is what I got:
import os.path
import posixpath
os.path
module 'posixpath' from '/home/xxuser/qiime_software/python-2.7.3-release/lib/python2.7/posixpath.pyc'
posixpath
module 'posixpath' from '/home/xxuser/qiime_software/python-2.7.3-release/lib/python2.7/posixpath.pyc'
Looks like os.path is there.
Could this have to do with a permissions error? I have it installed to /root/Canopy/canopy and I found this: docs.python.org/2/library/os.html#module-os (section 15.1.4). Does that make sense?
I'm also not sure if the following is related, but it might possibly. I can no longer seem to update my path with sys.path.append('/file/path/here'). It works until I close the terminal, then I have to re-append the next time I want to call a module from the new directory. Are sys.path and os.path related in any way?
Just fixed this on OSX with:
brew uninstall python
brew install python
No idea why, never seen it in 5 years of working with Python :S
It turns out that I was onto something with my last comment.
I'd downloaded a bunch of biology modules that depend on python, and so many of them came with their own install. When I added the modules to ~/.bashrc, my bash began calling them in advance of my original CentOS install. Resetting ~/.bashrc and restarting (for some reason source ~/.bashrc didn't work) eliminated all of the extra stuff I'd added to my $PATH and Canopy began working again. I'm going to go through and remove the extra installations of python and hopefully the issue will be behind me. Thanks to everyone who posted answers, especially A.J., because that's what got me thinking about .bashrc .
Edit: With some better understanding, this was all because of using python in a virtual environment. Canopy was resetting my path every time I opened it. I'm using a self-installed virtual environment now and have configured my path.
Try seeing if you have posixpath by typing import posixpath:
>>> import os.path
>>> os.path
<module 'posixpath' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc'>
>>> ^D
bash-3.2$ python
>>> import posixpath
>>> posixpath
<module 'posixpath' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc'>
>>>

How to run a.py file in python cmd?

I'm a newbie to python, so I just installed python27 on my win8 machine and set the path for C:\Python27 and C:\Python27\Scripts.
Now I want to execute a small .py file, so at the shell (python cmd) I type:
python "c:\python27\gtos.py"
File "<stdin>", line 1
python "c:\python27\gtos.py"
^
SyntaxError: invalid syntax
Any help is appreciated...
Thanks
Treat it like a module:
import file
This is good because it's secure, fast, and maintainable. Code gets reused as it's supposed to be done. Most Python libraries run using multiple methods stretched over lots of files. Highly recommended. Note that your import should not include the .py extension at the end.
Use the exec command:
execfile('file.py')
But this is likely to go wrong very often and is kind of hacky.
Spawn a shell process:
import subprocess
import sys
subprocess.check_call([sys.executable, 'file.py'])
Use when desperate.