[Tutor] downloading modules for both python 2 and 3

Mats Wichmann mats at wichmann.us
Sun Apr 9 09:50:20 EDT 2017


On 04/09/2017 02:20 AM, Peter Otten wrote:
> Benjamin Fishbein wrote:
> 
>> I’ve been writing an app using Kivy, and now I want to test it out on an
>> iPhone. However, this can currently only be done in Python 2.
>> https://kivy.org/docs/guide/packaging-ios.html
>> <https://kivy.org/docs/guide/packaging-ios.html> But when I import kivy in
>> Python2, I get an ImportError. ImportError: No module named kivy So I need
>> to install kivy for Python 2. But when I do:
>> sudo pip install kivy
>> I get the following:
>> Requirement already satisfied: requests in
>> ./anaconda/lib/python3.5/site-packages (from Kivy-Garden>=0.1.4->kivy)
>>
>> Do you know how I can convince my computer to download a module for Python
>> 2 when I already have it for Python 3?
> 
> On my (Linux) system there are multiple versions of pip, called pip2, pip3, 
> pip3.7; you might look for those.
> 
> Or you try to pick the desired interpreter with
> 
> $ sudo /path/to/desired/python -m pip install kivy

I'd highly suggest building a virtualenv for work requiring a specific
project to be installed. When doing that, you can call out the Python
you want involved, something like this sequence I just ran:

$ virtualenv -p /usr/bin/python2 kivywork
Already using interpreter /usr/bin/python2
New python executable in /home/mats/kivywork/bin/python2
Also creating executable in /home/mats/kivywork/bin/python
Installing setuptools, pip, wheel...done.
$ cd kivywork/bin
$ source activate
(kivywork) $ pip install --upgrade pip
Requirement already up-to-date: pip in
/home/mats/kivywork/lib/python2.7/site-packages
(kivywork) $ pip install --upgrade setuptools
Requirement already up-to-date: setuptools in
/home/mats/kivywork/lib/python2.7/site-packages
Requirement already up-to-date: appdirs>=1.4.0 in
/home/mats/kivywork/lib/python2.7/site-packages (from setuptools)
Requirement already up-to-date: packaging>=16.8 in
/home/mats/kivywork/lib/python2.7/site-packages (from setuptools)
Requirement already up-to-date: six>=1.6.0 in
/home/mats/kivywork/lib/python2.7/site-packages (from setuptools)
Requirement already up-to-date: pyparsing in
/home/mats/kivywork/lib/python2.7/site-packages (from
packaging>=16.8->setuptools)
(kivywork) $ pip install kivy
Collecting kivy
  Downloading kivy-1.9.1.tar.gz (16.4MB)
    100% |████████████████████████████████| 16.4MB 91kB/s
    Complete output from command python setup.py egg_info:
    Using distutils

    Cython is missing, its required for compiling kivy !


    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-ZXsSua/kivy/setup.py", line 184, in <module>
        from Cython.Distutils import build_ext
    ImportError: No module named Cython.Distutils

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in
/tmp/pip-build-ZXsSua/kivy/
$


Well, you get the idea.  I couldn't finish the install for the reason
listed.  With a virtualenv you get a controlled environment specifically
for what you want to do; the "activate" step gets it going, and changes
your prompt to show you you're in that environment. Should you need to
clean up now, it's a snap - just remove the virtualenv directory; you
have not messed with your "system" python.




More information about the Tutor mailing list