0

I am running Pycharm under Ubuntu and am trying to get Kivy installed in my project (virtualenv). I followed the Kivy instructions but those install it in the default environment. So, at my terminal prompt when I go into python I am able to successfully "import kivy". However, when I am in a Pycharm project with virtualenv, I get an error when I try to import from the Python console:

import kivy
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/mnt/bigdisk/apps/pycharm-2017.3.4/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 20, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: No module named kivy

I've even tried activating the virtualenv in my terminal and then performing the installation instructions. When I do this, I am told it is already installed. I think this is happening because to install kivy you have to make a sudo call (sudo apt-get install python-kivy) which is resetting the environment. I even tried sudoing to bash activating the environment and installing python-kivy, but again, it said it was installed. How do I get Kivy installed in my Pycharm virtual environment?

GregH
  • 12,278
  • 23
  • 73
  • 109

2 Answers2

4

Kivy Virtual Environment Installation using PyCharm

Assumption

Assuming virtualenv or/and virtualenvwrapper already installed.

sudo pip install virtualenv virtualenvwrapper

Launch PyCharm

  1. Click Congfigure
  2. Click Settings
  3. Click project Interpreter
  4. Click cogwheel next to the Project Interpreter field, and choose the option Add...
  5. New environment is the default selection.
  6. Type kivyinstall for the Location e.g. /home/iam/.virtualenvs/kivyinstall
  7. Select Base interpreter e.g. Python 3.5, or Python 2.7 from the drop down list.
  8. Do not select the Inherit global site-packages check-box.
  9. Select the Make available to all projects check-box, if needed.
  10. Click OK button
  11. After pip and setuptools installed, click + beside the column heading, Latest.
  12. Type cython in the search text input box under Available Packages Dialog.
  13. Select Specify version check-box to load version 0.25.2 which is compatible to Kivy version 1.10.0
  14. Click Install Package button.
  15. After cython 0.25.2 version installed successfully, type kivy in the search text input box under Available Packages Dialog.
  16. Click Install Package button.
  17. After kivy installed successfully, create a new project.
  18. In your opened new project, if kivyinstall did not appear in the expanded External Libraries then click File » Settings... » Project Interpreter and select Python...(kivyinstall) e.g. Python 3.5 (kivyinstall)

Print Screens

Img01 - Click cogwheel and select Add... Img02 - Create virtualenv kivyinstall Img03 - Virtualenv kivyinstall created and Python3.5 Img04 - Click + to install packages Img05 - Install Cython verion 0.25.2 Img06 - Cython installed Img07 - Install kivy Img08 - Kivy installed Img09 - Hello world Kivy App

ikolim
  • 15,721
  • 2
  • 19
  • 29
  • Well, I did all of this, but Kivy still doesn't install and still no errors. The Kivy-Garden package is there along with other packages, but no "Kivy" package listed for the "kivyinstall" interpreter that I set up. – GregH Apr 25 '18 at 05:04
  • What was the Cython version installed? – ikolim Apr 25 '18 at 14:20
  • I believed that Kivy was not installed because the Cython version installed is not compatible with Kivy. Please remove it and install Cython version 0.25.2 and then install Kivy. – ikolim Apr 25 '18 at 15:00
  • @ikolim This is the best answer and worked for me. – Hmerman6006 Jul 26 '19 at 20:27
0

apt-get install python-kivy installs kivy for a system interpreter and not inside a virtualenv no matter what sudo tricks you did. There's a special paragraph in the official docs for installing kivy inside a virtualenv: https://kivy.org/docs/installation/installation-linux.html#installation-in-a-virtual-environment

Pavel Karateev
  • 7,737
  • 3
  • 32
  • 59