2
votes

I have a Conda environment in which I installed the KivyMD package via pip (inside the environment).

In a PyCharm project, I copied the example code from KivyMD documentation. This project has my conda environment as interpreter. The interpreter is working perfectly with this (other files, which use other packages) and other projects. But I keep getting errors when trying to run the file with this package.

The code from the example, that I'm trying to run (https://kivymd.readthedocs.io/en/latest/getting-started.html):

from kivymd.app import MDApp
from kivymd.uix.label import MDLabel


class MainApp(MDApp):
    def build(self):
        return MDLabel(text="Hello, World", halign="center")


MainApp().run()

"Error: ModuleNotFoundError: No module named 'kivymd.app'; 'kivymd' is not a package"

I've tried uninstalling and reinstalling it again, but got the same problem. The package shows correctly both in "conda list" in the environment and in the PyCharm packages panel. Both Python and Pip used by Conda are in folders inside the environment folder as well (checked with "where" command). I'm using Windows and I double checked that I have the latest Anaconda version.

I've tried running the file directly on command line (outside PyCharm), but got the same problem as well.

How can I fix this?

2
have you activated the codna environment in terminal before installing or running the code ?sahasrara62
yes. as mentioned, I have no problems running other projects using this environment as interpreter.Luis Magalhaes
have you installed kivy framework in your system ?sahasrara62
the regular kivy package, yes. and I have successfully ran a couple of kivy projects using the same interpreter.Luis Magalhaes
try doing same whole procedure by creating a new environment specific for the projectsahasrara62

2 Answers

0
votes

Firstly I assume you are using python 3.8

Secondly have you installed kivy first following instructions here: https://kivy.org/doc/stable/installation/installation-windows.html

I did this from the conda command line on windows, which you can access either by your usual method or straight from the conda navigator. Make sure you check that the environment you want to be running this in is active by running

conda info --envs

If this returns nothing then conda is not working, this should return something that looks like this, but with filepaths after each environment name.

enter image description here

  • indicates the active env so if the environment you want isn't active use this to activate it:

    conda activate envname

If not go back and do this from within your conda env on command line then run the following in your conda env to install kivyMD:

    git clone https://github.com/kivymd/KivyMD.git --depth 1
    cd KivyMD
    pip install .

Provided you have no error messages, try compile your code to get it to run, I would recomend staying in the env activated command line to do this.

0
votes

I could only make it work with the following steps:

  • (maybe not necessary) Create a new environment in Conda
  • Install Kivy from conda forge (conda install)
  • Installed Kivy again with pip (pip install)
  • installed KivyMD with pip (pip install)
  • (maybe not necessary) created a new project in PyCharm
  • setup the new environment as interpreter

There was some conflict that Conda was not recognizing the pip package to run the project (and to run only). Apparently it was solved by installing the required Kivy package twice, both as conda AND as pip package. It seems that, at least in my case, it was necessary to "bridge" the 2 installations, though I don't know why.