3

Windows: I have the Python package CVXOPT installed on my computer for the regular Python distribution, though not specifically with Anaconda, so it imports fine when I'm doing text editor/cmd python scripting. I tried installing CVXOPT with Anaconda, but that didn't work so I'm having to import the library directly when working with iPython.

My directory structure looks like:

C:
--Python27
----Lib
------site-packages
--------cvxopt
----------__init__.py
----------.....

The error occurs when I run this code in an iPython notebook:

import sys
sys.path.append('C:\Python27\Lib\site-packages\cvxopt')
import cvxopt

The error:

ImportError: No module named cvxopt

How can I fix this? Perhaps I'm appending the path incorrectly?

Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
covariance
  • 6,833
  • 7
  • 23
  • 24

2 Answers2

5

You're defining a path a bit too deep in your file tree. You need to add to sys.path the folder just before your module:

import sys
sys.path.append('C:\Python27\Lib\site-packages')

import cvxopt

Here, cvxopt can be found in the site-packages folder. If you add the cvxopt folder in the sys path, it'll search a module of that name in the folder itself and will not checked the base folder.

Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
3

Import the path which contains the cvxopt package.

import sys
sys.path.append('C:\Python27\Lib\site-packages')

import cvxopt
Sudipta
  • 4,773
  • 2
  • 27
  • 42