2

I'm using PyCharm as my editor and seemingly it doesn't behave well with certain sub-modules namely numpy.random.normal. Not to be disheartened I tracked down where numpy.random lives to /usr/lib/python2.7/dist-packages/numpy/random.

I can't see any instance of normal. There's the definition for it in __init__.py but no actual code for me to copy into a new class for my project.

Am I looking in the wrong place for the code?

3
  • 2
    Why do you want to see the source? What is the problem you are having? These functions are implemented in C, see e.g. github.com/numpy/numpy/blob/master/numpy/random/mtrand/… Commented Feb 21, 2015 at 18:50
  • Whenever I try to import it into PyCharm using noise = numpy.random.normal(0, power_noise, len(self.data)) it tells me it cannot find the reference. If I open a terminal, however, I can use the normal function as I desire. Commented Feb 21, 2015 at 19:09
  • 1
    This looks like a PyCharm bug (indeed, their bugtracker lists several bugs like this). It's a commercial product, so take your problem to the software's developers. Commented Feb 21, 2015 at 23:03

1 Answer 1

3

You can find out, where a package is located by doing so:

import numpy.random
print numpy.random.__file__

In your case, it seems that the main parts of the module are implemented in C. You can see in the directory, that there is a file "mtrand.so" located in it. This is a shared object that was created from C sources, which are typically not delivered with the runtime package. The Python system can load such shared objects at runtime, when you import the module/package.

Sign up to request clarification or add additional context in comments.

3 Comments

So even though it gives me a warning before I run it, whenever I run the actual program it should behave as desired?
Can you give the complete error message? I am not familiar with PyCharm. Could it be, that the system has different PYTHONPATH? Is it using the same Python version???
normal is definitively implemented in mtrand.so on my system. I don't know, what is with your PyCharm system -- it must have something to do with PyCharm or PyCharm is accessing a different version of Python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.