Newbie question about importing modules

Posted by ronstrw on 2011-03-12 15:37

Forgive the very basic question...

I just installed ActiveState Python. It was installed in C:\Python27.

I then used to PyPM to install several modules. They were apparently installed in C:\Documents and Settings\Ron\Application Data\Python.

Since this was all done via the ActiveState install packages, I would assume that if I start the Python interactive editor and try to import module, it should work fine, but instead I get get errors. For example,

>>> import numpy

results in errors, (see below). On the other hand, if I open a command window and change to the directory,

C:\Documents and Settings\Ron\Application Data\Python\Scripts

and then start Python, the above import command appears to work fine, (i.e. no error messages are returned).

Am I missing some step using the ActiveState install packages? I was hoping the install packages would properly identify paths and working directories. I must just be missing something. Any help would be appreciated.

ActivePython 2.7.1.4 (ActiveState Software Inc.) based on
Python 2.7.1 (r271:86832, Feb  7 2011, 11:30:38) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import numpy

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import numpy
  File "C:\Documents and Settings\Ron\Application Data\Python\Python27\site-packages\numpy\__init__.py", line 136, in <module>
    import add_newdocs
  File "C:\Documents and Settings\Ron\Application Data\Python\Python27\site-packages\numpy\add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "C:\Documents and Settings\Ron\Application Data\Python\Python27\site-packages\numpy\lib\__init__.py", line 13, in <module>
    from polynomial import *
  File "C:\Documents and Settings\Ron\Application Data\Python\Python27\site-packages\numpy\lib\polynomial.py", line 17, in <module>
    from numpy.linalg import eigvals, lstsq
  File "C:\Documents and Settings\Ron\Application Data\Python\Python27\site-packages\numpy\linalg\__init__.py", line 48, in <module>
    from linalg import *
  File "C:\Documents and Settings\Ron\Application Data\Python\Python27\site-packages\numpy\linalg\linalg.py", line 23, in <module>
    from numpy.linalg import lapack_lite
ImportError: DLL load failed: The specified module could not be found.
>>>

sridharr | Sat, 2011-03-12 19:51

Hi,

It looks like you are hitting this bug:
http://bugs.activestate.com/show_bug.cgi?id=89474

Please try one of the following workarounds and report back if they work:

1. Reboot your computer, or
2. pypm -g install numpy
3. Manually add "C:\Documents and Settings\Ron\Application Data\Python\Scripts" to your %PATH% (the installer automatically adds '%APPDATA%\Python\Scripts" to %PATH%, but due to a bug in Windows, this is not expanded properly)

I always thought that (1) alone would fix this issue, but - as Iku, the bug reporter, noted - it seems that (3) is what actually fixed it for him. But (2) may be the simplest approach.

In any case, I need to look into the %APPDATA% issue properly.

-srid

ronstrw | Sat, 2011-03-12 21:09

Thanks for the quick response. As with the previous user, rebooting did not solve the problem, but manually changing the path did.

System Properties
Advanced Tab
Environment Variables

Change user variable PATH

from %APPDATA%\Python\Scripts

to C:\Documents and Settings\Ron\Application Data\Python\Scripts

I did not try option 2, but in some ways that does seem like a cleaner solution. It is working now though, so I'm happy. Thanks!

ronstrw | Sun, 2011-03-13 12:23

Okay, so being curious I decided to try option 2, (to install the packages with "pypm -g install". First I uninstalled all the packages I had previously installed. (I did not uninstall, "as.mklruntime 1.2 Intel MKL runtime files (Windows only)" since I did not install that myself via pypm). Then I reinstalled each one with "pypm -g install". Everything installed fine to c:\python27\Lib\site-packages, but now if I run "pypm list" I only see "as.mklruntime 1.2 Intel MKL runtime files (Windows only)". None of the other packages are listed. They work fine though, so I know they are there.

I did go back and change the user PATH variable to read c:\python27\Scripts. I didn't expect that to change anything since that was already part of the global PATH variable. I ended up deleting the user PATH variable altogether, (no other paths were defined). Everything I installed works fine, but "pypm list" shows only "as.mklruntime 1.2 Intel MKL runtime files (Windows only)"

sridharr | Sun, 2011-03-13 14:04

Try running "pypm -g list". Basically, "-g" option works on your global install, otherwise .. by default, %APPDATA% will be used. (Ideally "pypm list" should list packages from both global and local install; this may be implemented in future)

I did go back and change the user PATH variable to read c:\python27\Scripts

BTW, this is not required as the ActivePython installer already does this.

All that said, I think in your case option 3 is best. You don't have to worry about global vs local packages.

ronstrw | Sun, 2011-03-13 14:52

That worked. Thanks again for you help.

mrishnaa | Sun, 2014-11-16 05:26

I have installed modules globally. I can manually import all the modules in the IDLE but when i run in some applications it throws the below error. I have followed all the steps mentinoed in the page but nothing works. Don't know where i am doing mistake

Error] (L172: c0): Traceback (most recent call last):
File "", line 172, in Test_Main
import rg_alm_plugin_config as plat
File "C:\Demo_Regression\rg_alm_plugin_config.py", line 51, in
from fabric.api import *
File "C:\Users\Administrator\AppData\Roaming\Python\Python27\site-packages\fabric\api.py", line 9, in
from fabric.context_managers import (cd, hide, settings, show, path, prefix,
File "C:\Users\Administrator\AppData\Roaming\Python\Python27\site-packages\fabric\context_managers.py", line 42, in
from fabric.state import output, win32, connections, env
File "C:\Users\Administrator\AppData\Roaming\Python\Python27\site-packages\fabric\state.py", line 9, in
from fabric.network import HostConnectionCache, ssh
File "C:\Users\Administrator\AppData\Roaming\Python\Python27\site-packages\fabric\network.py", line 33, in
sys.exit(1)
SystemExit: 1