kivy with pycharm import error - python

(New in python+kivy here).
Hi, I'm trying to get python with Kivy up in running and I just wanted to know if there's a way to run Kivy apps in PyCharm since I'm getting an error:
Traceback (most recent call last):
File "C:/Kivy/kivy/examples/tutorials/pong/main.py", line 1, in <module>
import kivy
ImportError: No module named kivy
when loading this file with pycharm, notice that that's the sample game out of the box, I can run the app via right click->sendTo->kivy.bat but I don't think that large scale apps actually do it that way -.- there must be a simpler(and hopefully more graphic) way to use Kivy, after a lot of asking to Dr. Google I give up, Thanks in advance!:)
BTW: My main interest is making apps that makes basic database requests and at the same time are GUI friendly , Kivy was my first option next to WX but if there are any suggestions they are welcome :)

I just put up a tutorial on how to setup pycharm & kivy on os x
Short Version for Windows (I assume this will work):
After you install kivy, you need to create a python interpreter for kivy - if you already had python installed, it's the wrong python to do Kivy work. Check C:/Kivy/kivy/ or the contents of kivy.bat to get the path to the python.exe distributed with kivy ( I found C:\Kivy141\Python\python.exe on one page, but that may be if you install kivy manually)
When you find it, your kivy project python interpreter needt to be that one.
Good luck!

With PyCharm on OSX I had the same problem and solved it by creating a VirtualEnv in PyCharm (see PyCharm docs for this) and some Kivy paths to the virtualenv. You can find this by selecting the VirtualEnv and select the tab "Paths".
You can probably find out the correct paths by inspecting the kivy.bat file. I did something similar on the Mac.
I wanted to include a picture to show my paths settings, but my Stackoverflow karma level doesn't allow this.

PyCharm 4.0 changed the answer, now it's just set some environment variables. I updated the Kivy Wiki for setting up PyCharm on OSX

For OSX 10.10.2, kivy 1.9.0, and Pycharm 5.0.2 (free Community Edition), the instructions at the link below worked for me:
Setting up Kivy 1.9.0 with PyCharm 4.5 EAP on OS X 10.10.3
Substitute PyCharm for PyCharm-EAP in the instructions(which only occurs once).
I entered each Environment variable separately, rather than pasting them in as one long string.
Pay attention to the titles of the windows where you enter things. The instructions tell you EXACTLY which window you should be looking at.

To anyone that may see this:
Follow the wiki guide to create the symlink.
In Pycharm, add a local file for the project interpreter, then click the "more" button, go to the pencil, and manually change the link to /Applications/Kivy.app/Contents/Resources/script . That's how I got mine to work, latest PyCharm CE, Kivy, Python 3.5, and El Capitan

Related

RecycleView causing Kivy executable to crash

I followed the directions in the Kivy documentation on how to package applications for Windows, but my application crashes as soon as I try to run it. The last line of the traceback suggests a problem with my RecycleView widget:
File "C:\Users\awende\AppData\Local\Continuum\Anaconda3\lib\site-packages\kivy\factory.py", line 139, in __getattr__
module = __import__(name=item['module'], fromlist='.')
ModuleNotFoundError: No module named 'kivy.uix.recycleview.__init__.'
Failed to execute script SingleTabApp
I have tried importing kivy.uix.recycleview in all my .py and .kv files that it wasn't already imported in, but this doesn't seem to be the problem. I am not sure if this is a problem with my code, or if something else is going on.
Other potentially relevant information:
I am using Python 3.6.1 with the current dev version of PyInstaller.
Kivy version 1.10.0
SingleTabApp is the name of my main Python script, and was working correctly prior to using PyInstaller.
install a recent version of cython, notice that for a version of cython there is a corresponding version of kivy. To implement RecycleView, the version of kivy in your "package apk" not your computer must be at least 1.10
I ran across the same problem with PyInstaller on Windows 7. I appied a quick fix to factory_registers.py and it worked! (https://github.com/kivy/kivy/issues/5276)
A quick fix for the issue with pyinstaller is to change e.g. r('RecycleViewBehavior', module='kivy.uix.recycleview.init') to r('RecycleViewBehavior', module='kivy.uix.recycleview').
PS factory_registers.py also has r('RecycleView', module='kivy.uix.recycleview.__init__'), I didn't touch it.

wxPython for Framework distribution rather than Conda

I've been struggling with getting wxPython work - I'm running a Mac, OSX 10.11.6 El Captain, so the pip install runs into /src/osx/cocoa/mediactrl.mm:52:10: fatal error: 'QTKit/QTKit.h' file not found with the new XCode, and some changes there, and won't compile. So I found an installer, that at least gets it done.
But then wx runs (I only tried to import it in fact) in my conda python 2.7.12.
My goal is to be able to play around with TensorKart and since my default python is conda, when attempting to run the repo, it tells me the usual:
This program needs access to the screen.
Please run with a Framework build of python, and only when you are
logged in on the main display of your Mac.
I found how George Reilly explains here what to do, but I cannot find the wxredirect.pth and don't know what to do with the bash script. I only have wx.pth within the conda site-packages.
So is it somehow possible to get the wxPython for my Framework 2.7.10 with the .dmg installer? After 6 hours of struggle it seems like the easiest way.
I tried:
copy conda site-packages having to do with wxPython into site-packages within a virtualenv created form the Framework Python as it was in the original G. Reilly's post which no longer works.
create alias in .bash_profile that python is the Framework version but it didn't help.
Thanks a lot!

Fixing Python 3 tkinter issues on Mac with a virtualenv

I think the short version of this question is: How do I get a virtualenv running Python 3.5 to point to the correct version of ActiveTcl on a Mac?
Here's the longer version:
I'm trying to run this Korg Electribe sample editor project on a Mac. The author has only tested it on Windows, and based on the screenshots, it appears to work. I've been able to run the basic python script fine, but as I mention in an issue that I've opened, the full window turns black after loading a file.
After doing some research, I've found that there is a known issue with Aqua Cocoa Tk, and python.org has provided some instrunctions about how to fix tkinter for Mac OS 10.9 and up. I've attempted installing both of the suggested ActiveTcl (8.5.18.0) as well as the newer 8.6.x.x version without success.
I'm pretty sure this is a different issue than Tkinter not working mac osx el capitan, since the script does run, and the window is drawn properly on launch. It's only after I've attempted to load a .all file (there's a sample file in the Github issue) that the screen goes black.
After some more research, I've found this question that seems related, but is specific to Windows: TKinter in a Virtualenv
I'm under the impression that if I can figure out what to set TCL_LIBRARY to, that I'll be able to make some head-way, but I can't seem to find that information for the packages listed on python.org.
Somewhat related, it would also seem to be helpful if I could figure out which version of Tcl/Tk that tkinter is pointing to from within Python, so if anyone could help with that as well, I'd greatly appreciate it.
Thanks!
I succeeded in using tkinter in a python3 virtualenv on OSX 10.13 by :
installing the official OSX Python 3 from https://www.python.org/
installing activeTcl from https://www.activestate.com/activetcl
creating a new virtualenv
mkvirtualenv myenv --python=python3
locating the tkinter location in the Python3 directory. For me it was here :
/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter
creating a symbolic link in the virtualenv library pointing to the tkinter location
cd ~/.virtualenvs/myenv/lib/python3.6
ln -s /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter tkinter

The PIL library import fails

Being a complete begginer in python, I decided to install the python interpreter 3.4.4, and also PyDev plugin for eclipse IDE. I am also using windows 10.
I have encountered a problem regarding certain imports, namely : from PIL import Image, ImageTk, which is apparently an unresolved import.
I have looked at certain questions which were similar to my situation, but most of them gave a solution like installing packaged from the linux apt-get. Here are some topics I visited :
Uninstalling and reinstalling Pillow and pip,
Installing pillow-imaging-tk on Ubuntu,
This topic which left me very confused,
This one seemed helpful, but is on Unix OS again
So please, could someone explain to me why I am seeing this error, and how could I correct it if I absolutely want to use Eclipse, Pydev, windows 10 and Python 3.
Found the solution, here's what I did:
Set the PYTHONPATH like it is shown in this article, make sure python.exe is accessible via cmd,
Via cmd, type pip install pillow. Alternatively, you can enter the same command from Windows+R,
(Not sure if relevant step) Via eclipse, Windows->Preferences->PyDev->PythonInterpreterremove your interpreter to re-add it,
Restart eclipse.
For Python import problems in PyDev, the project web site has a page on interpreter configuration that is a good place to start. I recently had a similar problem that I solved by adding a module to the forced builtins tab.

How to install python modules on mac

I'm a complete beginner in Python programming. I have trouble installing/importing the module 'requests' on python. When I use my command terminal to install requests, I get a message that requests is already installed. However, when I try to import requests into the file I'm working on, python tells me there is no such module installed.
Sorry to bother you with this silly and probably easy question, thanks in advance!
If you use PyCharm (which is a great choice in my opinion), go to the tab Run and select Edit Configuration and in the window that just opened make sure the your Python interpreter is the one you used when you pip installed the package you asked about.
You can check your Python version or just see in PyCharm if the requests is actually installed by going to the tab File, select Settings, click on Project: name_of_your_project and finally check in Project Interpreter that the package is installed.

Categories

Resources