Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8362027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:50:43+00:00 2026-06-09T11:50:43+00:00

I imported a numpy library in two different ways. The first time with from

  • 0

I imported a numpy library in two different ways. The first time with from numpy.random import mtrand and the second time after messing with the sys.path.

However, the output of these two module imports was totally different:

>>> from numpy.random import mtrand
>>> dir(mtrand)
['RandomState', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__test__', '_rand', 'beta', 'binomial', 'bytes', 'chisquare', 'dirichlet', 'exponential', 'f', 'gamma', 'geometric', 'get_state', 'gumbel', 'hypergeometric', 'laplace', 'logistic', 'lognormal', 'logseries', 'multinomial', 'multivariate_normal', 'negative_binomial', 'noncentral_chisquare', 'noncentral_f', 'normal', 'np', 'pareto', 'permutation', 'poisson', 'power', 'rand', 'randint', 'randn', 'random_integers', 'random_sample', 'rayleigh', 'seed', 'set_state', 'shuffle', 'standard_cauchy', 'standard_exponential', 'standard_gamma', 'standard_normal', 'standard_t', 'triangular', 'uniform', 'vonmises', 'wald', 'weibull', 'zipf']

And the second one:

>>> sys.path.insert(0, '/usr/lib/pymodules/python2.7/numpy/random')
>>> import mtrand
>>> dir(mtrand)
['__builtins__', '__doc__', '__file__', '__name__', '__package__']

How is this behaviour possible?

Edit:

  • These two tests were executed in different python processes.
  • Messing with the sys path is stupid, I know that. But this is not for a normal program, it’s for an autocompletion. I certainly don’t want to import the whole numpy package. I just want to be able to make a dir(mtrand)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:50:45+00:00Added an answer on June 9, 2026 at 11:50 am

    As Endophage pointed out, it is indeed stupid to play with the sys.path. But I guess I started it, because I did not want to execute any Python code, which would be quite cool for an auto-completion. I didn’t think that this is a big issue for c_builtin modules. However, there are modules, which really need the correct package path (see the comment about segfaults further down).

    I even did a workaround for PyQt4, but noticed that this would not be the only workaround:

    sys.path.append('/usr/lib/python2.7/dist-packages/PyQt4')
    try:
        import QtCore
    except SystemError:
        QtCore = sys.modules['PyQt4.QtCore']
        debug.warning('Loaded a module with SystemError.') 
    

    This included catching a SystemError and then using it from sys.modules. Indeed this is very stupid, because I don’t know about any side effects of such operations. As I tested PySide (which is another Qt wrapper), segfaults happend under certain circumstances.

    So I came up with the more pythonic solution to load modules like this again: from PyQt4 import QtCore and from numpy.random import random.

    Interestingly, the memory footprint for loading those modules with their full path, was about as much as messing with the sys.path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At first i have imported #import GDataXMLNode.h in .h file. Now this is my
After a repository is imported from VSS to SVN, there are some files which
I have a numpy array (actually imported from a GIS raster map) which contains
I imported data from MySQL to a CSV. Now I am trying to import
I imported a sample 4.0.3 project and after deleting it from the Project Explorer
I imported data from MS-Access into a SQL database using the import/export wizard. Now,
Can MlPy / SciPy be used on GAE? I believe I have imported NumPy
I imported an excel file into my database using Tasks -> Import -> Excel
I have imported a JSF/Facelets project from SVN into Netbeans. Any change which I
I imported a table from a CSV file into MySQL using this query: LOAD

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.