-1

I have created my first python module on ubuntu. When I'm trying to import the module in python using :

import brian

it is giving error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named brian

I have brian in /home/noamaan and python is in /usr/bin.

Jon Clements
  • 138,671
  • 33
  • 247
  • 280
user1966225
  • 11
  • 1
  • 1

2 Answers2

3

If you launch python from the directory that contains brian module, everything will work as it is now.

To import custom module from anywhere you want you should read attentively something on the import mechanism in python to learn where the imported modules are searched for, etc.

But to make your code work right now, I can recommend you the following:

  • Either extend your PYTHONPATH variable before running python, to include the directory of your module
  • Or append it right in the code by using sys module in this way.

    import sys
    
    sys.path.append("path/to/module/dir")
    
    import brian
    

Also, see info on site module

Mikhail Karavashkin
  • 1,365
  • 10
  • 16
1

by default Python import modules from Python path var. You can view these paths so:

import sys

print sys.path

Community
  • 1
  • 1
Dmitry Dubovitsky
  • 2,186
  • 1
  • 16
  • 24