I've installed Kivy and all the need files as far as I know, but I'm still getting this error message and I don't know why.
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
class Container(GridLayout):
pass
class MainApp(App):
def build(self):
self.title = 'Awesome app!!!'
return Container()
if __name__ == "__main__":
app = MainApp()
app.run()
This is the error message I get:
Traceback (most recent call last):
File "C:\Users\Yassi\OneDrive\Afbeeldingen\Bureaublad\main.py", line 1, in <module>
from kivy.app import App
ImportError: No module named 'kivy'
I installed Kivy through anaconda, so the files for kivy might be installed in a wrong directory. Either way, I don't know how to fix this problem.
I'm running this program on a Windows 10 OS and I use python-3
Edit: It might have something to do with how I refer to the python interpreter. I can't find the location of the python interpreter though so now I'm stuck.
Edit2: This is the place where I installed python: C:\Program Files\IBM\SPSS\Statistics\25\Python3. Any way how I can refer to this? I think this is where the problem lies.
Check if in current enviroment you have kivy installed:
import pip._internal as pip
print([i.key for i in pip.get_installed_distributions()]
# or
pip.main(['freeze'])
So you will see if in this enviroment you have kivy installed.
To make sure you have kivy installed in this enviroment you can write something like this:
try:
from kivy.app import App
except ImportError:
import pip._internal as pip
pip.main(['install', 'kivy'])
from kivy.app import App
I was facing the same issue. After trying it multiple times, I came across this solution and it worked.
Basically, you need to create an interpreter which points to kivy folder('kivy_venv' folder which was created using steps similar to this installation link: https://kivy.org/doc/stable/installation/installation-windows.html#start-a-kivy-application
Open Pycharm
Click 'File' tab in upper left corner
click on 'Settings'
click on 'Project:test'
click 'Python Interpreter'
click on 'Settings symbol' (wheel shaped) next to 'Python Interpreter'
click on 'show all'
click on '+' plus symbol
Set 'Location' to the folder where 'PycharmProject' folder is situated.(To find out PycharmProject folder location, click on File->Open->ProjectName ) (I would recommend you to create a new folder in PycharmProject say 'kivyProject1') In my case, Location is C:\Users\Shraddha\PycharmProjects\kivyProject1
Set 'Interpreter' to the folder where kivy was installed.(If you installed kivy using steps at https://kivy.org/doc/stable/installation/installation-windows.html#start-a-kivy-application , you will have 'kivy_venv' folder. Copy the complete address of 'kivy_venv\Scripts\python.exe' and paste at 'Interpreter' ) In my case, Interpreter is C:\Users\Shraddha\AppData\Local\Programs\Python\Python37\kivy_venv\Scripts\python.exe
Click on 'Edit' (a pencil shaped symbol at right side) and set name Name: Python 3.7 (kivyenv1) Keep Location as it was.In my case Location is C:\Users\Shraddha\PycharmProjects\kivyProject1\Scripts\python.exe
Click OK. Then OK. Now you are out of 'Settings'.
Create new python program filename.py to check if kivy is imported. For that, Click File->Create new project and ensure its location is C:\Users\Shraddha\PycharmProjects\kivyProject1\filename.py
In filename.py, type import kivy and run by clicking on PLAY button. You must get logs as : succesfully imported kivy
I had the same error. Am using windows 10 in VS code and below is a solution that works:
The solution was to run this:
python -m pip install kivy==2.0.0rc1
I don't know why this works, but the website instruction appears to use an older version:
python -m pip install kivy==1.11.1 which fails.
You can test by running a kivyTest.py file with one line of code (below):
import kivy
Short answer:
1) Open an Anaconda command prompt.
2) Type code, and then press enter.
3) Now open your file and run your code in "this" VScode.
More explanation:
I was facing the same problem (installed kivy by running conda install kivy -c conda-forge in an Anaconda command prompt), and I couldn't import kivy in VScode that is opened normally and not from the Anaconda environment (got the ImportError: No module named 'kivy' error), but then I opened VScode from Anaconda Navigator, and run the same code and this time I didn't get any error. Then I searched if it was possible to open VScode from Anaconda command prompt (like when you want to open an IPython notebook with jupyer notebook), because the prompt loads much faster than the navigator. And found out it is done by typing code and pressing enter.
Hope this helps you!
if you installed it just restart your computer. I faced same problem I search on many sites
I don't get solution than shutdown pc next day I restart it its working.
I had a same problem with virtualenv in VS Code. The issue was that I should select Python interpreter from bin in virtualenv.
I had a same error and no solution that mentioned here worked for it!
It happen because of virtual environment and after activating it , everything goes well!
Related
I have installed Kivy and when I used the IDLE app that came with Python I can import it and it runs perfectly. However, when I try to import it in vscode I get the error:
ModuleNotFoundError: No module named 'kivy'. I can not find out what to do and the environment from the kivy dmg does not open so I feel lost. Can someone help me?
Two solutions
Check the python interpreter being used
When any .py file is open in the editor and is currently being used, near the bottom left, it says Python <version> <32/64>-bit. Tap it and select the directory that contains the python interpreter version that has kivy installed.
Check the following image for any help
The platform I was using was a chromebook, but the location of changing the editor is the same
Manually install within VScode
Run pip install kivy to ensure that vscode uses it
I've installed Kivy.....a lot of times.
I'm in VS Code and it shows in Libraries but I can't seem to figure out how to import.
Getting kivy module does not exist error.
Can run a .py file with just import kivy in the terminal with success.
Cannot run kivy built-in example from terminal. ErrNo2
You're opening python environment as current project. It's not recommended to do so, and we usually open a folder and select the python environment as interpreter.
Turn back to your question, make sure you've selected the opened environment as interpreter. Open Command Palette, click Python: Select intepreter then enter interpreter path. It will pop up a folder explorer, choose your current opened Scripts\python.exe, then you can import kivy successfully:
More information please view Python Tutorial and Python Environments.
I installed bottle on Python 3.4 with pip install. In the terminal, when I do:
$ python3.4
>>>import bottle # shows no import error
>>>
but when I do it in PyCharm, it says:
import bottle ImportError: No module named 'bottle'
in your PyCharm project:
press Ctrl+Alt+s to open the settings
on the left column, select Project Interpreter
on the top right there is a list of python binaries found on your system, pick the right one
eventually click the + button to install additional python modules
validate
In some cases no "No module ..." can appear even on local files. In such cases you just need to mark appropriate directories as "source directories":
The settings are changed for PyCharm 5+.
Go to File > Default Settings
In left sidebar, click Default Project > Project Interpreter
At bottom of window, click + to install or - to uninstall.
If we click +, a new window opens where we can decrease the results by entering the package name/keyword.
Install the package.
Go to File > Invalidate caches/restart and click Invalidate and Restart to apply changes and restart PyCharm.
Settings:
Install package:
I am using Ubuntu 16.04. For me, it was the incorrect interpreter, which was by default using the virtual interpreter from the project.
So, make sure you select the correct one, as the pip install will install the package to the system Python interpreter.
PyCharm 2019.3, my solution is below:
For me, none of the above worked, and curiously even within one file some imports worked, some didn't:
from folder1.folder2.folder3.my_python_file import this_function # worked
from folder1.folder2.folder3.my_python_file import that_function # didn't work
Follow the above advice, but if it doesn't fix it additionally, (in PyCharm) click File >> Repair IDE and confirm all the 6 steps one after another.
I had virtual env site package problem and this solved it:
In the case where you are able to import the module when using the CLI interpreter but not in PyCharm, make sure your project interpreter in PyCharm is set to an actual interpreter (eg. /usr/bin/python2.7) and not venv (~/PycharmProject/venv/...)
I had the same problem, I tried all fixes like installing from the project interpreter and installing from python console, nothing worked. What worked was just going to the project folder from the terminal and installing it from there.
When I try to import kivy,it says: No module named 'kivy'
On IDE it works. I will add a screenshot so that you could have a better look and maybe help me solve that problem.
It sounds like you are using a virtual environment in PyCharm and using the global environment or a different virtual environment in IDLE. You need to install kivy in the virtual environment you are using for it to work. There are several ways to do this. One is to position the worker in the import statement then press Alt-Enter. This should give a popup menu with an option to install kivy. Use the arrow keys to navigate to this option if necessary and then press Enter.
try to install kivy from python console in pyhcharm instead windows console maybe it will work
New to Kivy and PyCharm on Windows. Tried the Pong Game tutorial that was suggested on the Kivy website. Ran into the error displayed in the photo below. Installed Cython using pip as well. I have no clue as to what the problem is here.
[UPDATE]:
Tried the same program on IDLE, works just fine.
Screenshot of my project
[UPDATE #2]:
The screenshot above is the most recent picture of what i see on PyCharm.
You have to install kivy manually on pycharm, follow these six steps:
Click on Files on top left corner.
Click on settings.
Click on Project and click on project interpreter.
Click on (➕) icon on right.
Click on "Search" and type "Kivy" you will find a lot of packages, then choose Kivy and
install it.
Enjoy!
Usually PyCharm will complain in the editor with red squigglies underlining import kivy if it is not installed. I am not sure why it is not in your case. Perhaps your run configuration is using a different interpreter than the one used by the project for autocompletion and such. Click on the drop down at the top right, near the run button. Then click on Edit Configuration.... Make sure the interpreter is set to the project's default.
To install kivy in you venv from the command line, first activate it with
. /path/to/venv/bin/activate
Then run pip commands as usual.
I have just succeeded with
pip install https://github.com/kivy/kivy/archive/master.zip
But not with
pip install kivy
https://kivy.org/docs/installation/installation-osx.html
Running OS X, PyCharm 2018.1, pipenv, Python 3.6
Change project interpreter to system interpreter
file > setting > project > project interpreter > gear icon > system interpretor