Karnivaurus
Karnivaurus

Reputation: 24111

Importing modules that work in Python 2.7 but not Python 3.4

I have previously been using PyCharm with Python 2.7, and have been able to import the module sklearn, which was intalled via sudo apt-get install python-sklearn.

However, I have now changed the settings in PyCharm to use Python 3.4. Now, it gives me the error: ImportError: No module named 'sklearn'.

I suppose this is because sklearn was installed in /usr/lib/python2.7/dist-packages. But in /usr/lib/python3.4, there is no directory called dist-packages. However, I have a directory called /usr/lib/python3/dist-packages, which has just one directory, which is dist-packages.

Any idea on what I need to do to clean this all up?

Upvotes: 2

Views: 650

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121584

You'll need to install sklearn for Python 3.4. Ubuntu currently does not have a python3-sklearn package available, unfortunately, so you'll have to follow the installations instructions to install this yourself.

This includes installing build dependencies:

sudo apt-get install build-essential python3-dev python3-setuptools \
                     python3-numpy python3-scipy \
                     libatlas-dev libatlas3gf-base

You may have to set the right implementation (Ubuntu 13.04 and newer):

sudo update-alternatives --set libblas.so.3 \
    /usr/lib/atlas-base/atlas/libblas.so.3
sudo update-alternatives --set liblapack.so.3 \
    /usr/lib/atlas-base/atlas/liblapack.so.3

followed by

pip3 install --user -U scikit-learn

for a local install (your account only), or

sudo pip3 install -U scikit-learn

for a global install.

Upvotes: 3

Related Questions