Reputation: 83
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.
Upvotes: 2
Views: 22361
Reputation: 1
This was bugging me but I found the solution!
You need to change the interpreter to the python.exe in the Scripts folder for your virtual environment!
Add a new interpreter set to your virtual environment python.exe
Upvotes: 0
Reputation: 365
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!
Upvotes: 0
Reputation: 1
I had a same problem with virtualenv in VS Code. The issue was that I should select Python interpreter from bin in virtualenv.
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 109
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!
Upvotes: 0
Reputation: 5694
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
Upvotes: 1
Reputation: 11
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
Upvotes: 1
Reputation: 1502
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
Upvotes: 2