Kivy Installation Guide for Windows 10 - python-3.x

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.

Related

easy SublimeText question regarding pygame module

I've been using SublimeText on OSX without issue... until I tried to import pygame. A simple few lines of code like:
print("Hello")
import sys
import pygame
gets the following output:
Hello
Traceback (most recent call last):
File "/Users/andrewjmiller/Desktop/python_work/new_file.py", line 5, in <module>
import pygame
ImportError: No module named pygame
[Finished in 0.0s with exit code 1]
[shell_cmd: python -u "/Users/andrewjmiller/Desktop/python_work/new_file.py"]
[dir: /Users/andrewjmiller/Desktop/python_work]
[path: /Library/Frameworks/Python.framework/Versions/3.8/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Users/andrewjmiller/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
But... I do have pygame installed, as evidenced here:
iMac:~ AndyTheAdmin$ python3 -m pip install --user pygame==2.0.0.dev6
Requirement already satisfied: pygame==2.0.0.dev6 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (2.0.0.dev6)
I've uninstalled and reinstalled SublimeText3. What should I try next?
You're falling victim to the difference between Python 2 and Python 3. In particular, note the line in the Sublime diagnostic output that says what command it was that failed:
[shell_cmd: python -u "/Users/andrewjmiller/Desktop/python_work/new_file.py"]
The Python.sublime-build file that ships with Sublime tells the OS to execute the command python.
In your example where it works (or rather where you get confirmation that the library is installed):
iMac:~ AndyTheAdmin$ python3 -m pip install --user pygame==2.0.0.dev6
Here you're executing python3. Dollars to donuts if you were to type python --version in the terminal, it's Python 2 that Sublime is executing. The different versions of Python keep their packages in different locations, which is why it works in one place and not the other.
Assuming that this is the case, the solution is to use a build that executes python3 instead. If you're already using a custom build system, then you can modify it directly. If you're using the build that ships with Sublime, the easiest way to make a new build is:
Use View Package File from the command palette and open Python/Python.sublime-build to see what the existing build system looks like, and copy the entire thing to the clipboard.
Use Tools > Build System > New Build System, replace the content with what you copied above, then swap the python for python3 in the two shell_cmd lines so that they execute the version that you expect.
Save the file in the location that Sublime defaults to (should be your User package) as a sublime-build file with an appropriate name.
Once you save, the Build system will be made available. You can either select it from Tools > Build System to use it directly, or if you have the build system in that menu set to Automatic the next time you do a build Sublime should prompt you to pick the build to use since there is now new builds.

ModuleNotFoundError: No module named 'docx' on VScode but not in Python itself

I have installed the python-docx module using pip:
python -m pip install python-docx
However, when I try to run my script that only contains import docx, I get the following error
ModuleNotFoundError: No module named 'docx'
When I execute the following command in Python on the command line, it works fine:
import docx
When using Visual Studio Code, make sure that it uses the same Python version as you are using when running the script. You you should set the "python.pythonPath" setting correctly in settings.json (manually edit the file or edit in Visual Studio itself). This can be done system-wide (per user), or per project.
Furthermore, this answer gives some background about how Python files are executed in Windows.

ModuleNotFoundError: No module named 'gather_keys_oauth2'

I am trying to create a Python Script to get my hands on my Fitbit data so that I can alternately integrate it with another API. I have been following the instruction on this website https://towardsdatascience.com/collect-your-own-fitbit-data-with-python-ff145fa10873
I have used pip to install Fitbit, Pandas, DateTime and also Oauth. To install OAuth I used the following:
pip install oauth -t fitbitAPI
It installed without any issue.
I put the following lines into my Python Script:
import fitbit
import gather_keys_oauth2 as Oauth2
import pandas as pd
import datetime
When I test the script I get the following error message:
Traceback (most recent call last):
File "fitbitAPI.py", line 2, in <module>
import gather_keys_oauth2 as Oauth2
ModuleNotFoundError: No module named 'gather_keys_oauth2'
I spent hours searching the web but have not been able to find anything that's been helpful. Any ideas? Is there another version or way that I need to install OAuth?
Here's how I was able to resolve the error:
Download the fitbit package as described (https://github.com/orcasgit/python-fitbit).
After you install fitbit as described, navigate to the newly created folder \Lib\site-packages\fitbit
Copy and paste the gather_keys_oauth2.py file into the fitbit folder
Then you can from fitbit import gather_keys_oauth2 as Oauth2
One clarification on Jacob Miller's solutions:
Copy and paste the gather_keys_oauth2.py file into the fitbit folder
copy gather_keys_oauth2.py into the Lib/site-packages folder if the above still results in the not found error.
And, I installed cherrypy (required by gather_keys_oauth2.py) using the Anaconda Navigator:
screen shot from Navigator
good luck.
You should be able to source the module from orcasgit. You can download the python script here and stick it in your directory.
I experienced a similar issue and solved by updating my environment and making sure I was using python3. I had activated the wrong environment with the conda activate environmentname command, and so the notebook was throwing this same error.
Install Anaconda-Navigator
Create a new environment with the Anaconda-Navigator tool
Make sure you are using Python 3.x in this new environment
Install cherrpy using the Anaconda-Navigator tool
When you start-up terminal and navigate to the directory of your app, you'll activate your environment with conda activate environmentname and then start up your notebook jupyter notebook. This error should disappear.
Note: there may be some additional packages you need to install. Keep using the anaconda navigator to continue installing the packages; the error messages coming off the notebook will guide you to install the right packages.

PyCharm Import Error: Claims 'matplotlib' is not a package, but works successfully in IDLE

Happy October everyone,
I've successfully downloaded modules before using either the pycharm installer or pip through the command screen, but for some reason when installing matplotlib pycharm cannot recognize it. I've uninstalled and reinstalled, I've installed through both methods, I've followed past similar questions asked on this site which make sure that you have the same interpreter and that it was installed in the right folder (pycharm error while importing, even though it works in the terminal).
So, here's the whole problem. Here's is the simple code, submitted into both pycharm and IDLE:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[2,1,3])
plt.show()
When submitted into IDLE, my plot appears. When submitted into pycharm, the following error appears:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/PythonProject/matplotlib.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\PythonProject\matplotlib.py", line 1, in <module>
import matplotlib.pyplot as plt
ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I am currently running Python 3.4, PyCharm 2016.2.3, and my matplotlib folders are indeed in my site-packages folder inside my Python34 folder. Also for further verification:
PyCharm installation
Please help I've become frustrated since this is the only module I've run into trouble with. I've scoured StackOverflow and related websites to help, I've made sure I have all the requirements, etc.
I guess if you named your current writing python module as matplotlib.py.That cause the python load your current writing module instead of the actual matplotlib.py, which triggers an error.
I recommend you to use virtualenv. Is not strictly necessary but is good for dividing your project environments.
This is how I tested matplotlib on my Windows 10 installation, hope it helps.
Be sure that you have the python 3 installation folder listed in your Windows PATH environment variable, should be already listed if you checked "Add Python 3.5 to PATH":
You need also to set the Scripts folder in your PATH environment variable usually should be this path:
C:\Users\<your username>\AppData\Local\Programs\Python\Python35\Scripts
If you don't do that you have to prepend python -m to every command below like this: python -m <command>, so the command below would be python -m pip install virtualenv. I prefer the first solution.
To test matplotlib on Pycharm I've used virtualenv, here is how; first install virtualenv:
pip install virtualenv
Then you create your virtual environment in a folder of your choice, in my case I used python_3_env_00:
virtualenv python_3_env_00
After that you can activate you python 3 virtual environment:
python_3_env_00/Scripts/activate.bat
Now you should see in your command line the active virtual environment (python_3_venv_00), like this:
Now you can install matplotlib:
pip install matplotlib
Fire up PyCharm and add your virtual environment as you project interpreter, go to File->Settings search for Project Interpreter click on the gear icon and Add Local and set the path of your virtual environment, should look like something like this:
Test it:
import sys
print(sys.path)
run this code in where the import worked, and run it in the Pycharm project. Compare the lists. Find out which path that is not present in Pycharm sys.path.
Before importing pyplot, append the missing path to sys.path.
import sys
sys.path.append("the path")
import matplotlib.pyplot as plt
Does this work?
Please follow below steps if you are still getting an error:
If you are using PyCharm, it automatically create virtualenv.
Ensure Scripts path is set into PATH
C:\Users\<Username>\AppData\Local\Programs\Python\Python37-32
Then open PyCharm and go to File-> settings. Search for Project Interpreter. You will see window like this
sample image
Click on setting icon -> Existing Environment -> click on ... give below path
C:\Users\Krunal\AppData\Local\Programs\Python\Python37-32\python.exe
Click on Apply -> ok and you are good to go.
After installing matplotlib When I was trying to use matplotlib.pyplot it was giving error module not found.
I browsed some white papers and found out that we also need to install scipy library to use the matplotlib so I used the below in my command prompt
python -mpip install scipy
Restarted my kernel session.
It worked!!!
I was also facing issue while importing matplotlib but it got resolved and now I am able to use it from pycharm as well.
Please make sure you should have visual c++ 14 installed in your system.
2.If you have more than two python version installed on your system then please install matplotlib from both the version.
Eg. pip install matplotlib
pip3 install matplotlib
If matplotlib is working from python idle then please check whether you are using correct interpreter in pycharm or not and try to choose pythonw.exe path from your installed location.
Hope this will help, Please do let me know if you are still facing issue.
I had similar issue but I solved it very easily on pycharm 2019.3.2. In case anyone looking for an easier solution:
I just opened the terminal window on pycharm and typed pip install matplotlib and it was all good to go. Every project has its own virtual environment. Opening terminal window of IDE cds to project directory by default. So the installing command was enough.

How to install PyGObject on windows in a anaconda virtual env

I want to use Gtk with python under windows. I already have Anaconda installed on windows. In order not to mess up everything and to have some easiness uninstalling/reinstalling, I would like to have a virtual env created with conda, working with that Gtk installation. But I don't seems to be able to make it work.
Here is my process. I first create a raw Ananconda virtual env with
conda create -n gtk-exporter python
The virtual environment is located at C:\Anaconda3\envs\gtk-exporter.
I then download the latest windows installer for PyGObject at http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar
I extract and execute the installer and tell it to use a portable python install at C:\Anaconda3\envs\gtk-exporter. I only select Base, GTK and Glade for installation. The installation finished in a second and says it's successful.
Then within windows' shell, I activate the new environment with activate gtk-exporter. However when I try to import gtk, it fails, not finding gi.repository.
>>> from gi.repository import Gtk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'gi'
What's wrong here ? C:\Anaconda3\envs\gtk-exporter\Lib\site-package contains a folder gnome with a lot of stuff including *.dlls, *.exe's and unix-looking folders like etc, lib or share, but I don't see a init.py or something pythonic. Am I missing a step.
Thank you for your help !
The problem was that I used python 3.5, whereas it is not supported. The installer should not have allowed me to install with python 3.5. I filed a bug report to signal it.
I solved the problem by uninstalling python 3.5 and installing python 3.4.

Resources