Luis Magalhaes
Luis Magalhaes

Reputation: 47

Pip Package not being recognized in Conda

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?

Upvotes: 2

Views: 2163

Answers (2)

Luis Magalhaes
Luis Magalhaes

Reputation: 47

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.

Upvotes: 0

Merlindima
Merlindima

Reputation: 48

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.

Upvotes: 0

Related Questions