Skip to content

Tag: import

Can’t import my own modules in Python

I’m having a hard time understanding how module importing works in Python (I’ve never done it in any other language before either). Let’s say I have: Now I’m trying to get something like this: However, I’m definitely doing something wrong as Python can’t see that myapp is a…

Importing modules inside python class

I’m currently writing a class that needs os, stat and some others. What’s the best way to import these modules in my class? I’m thinking about when others will use it, I want the ‘dependency’ modules to be already imported when the class is instantiated. Now I’m importing t…

Python import src modules when running tests

My source files are located under src and my test files are located under tests. When I want to run a test file, say python myTest.py, I get an import error: “No module named ASourceModule.py”. How do I import all the modules from source needed to run my tests? Answer You need to add that director…

Check if module exists, if not install it

I want to check if a module exists, if it doesn’t I want to install it. How should I do this? So far I have this code which correctly prints f if the module doesn’t exist. Answer Here is how it should be done, and if I am wrong, please correct me. However, Noufal seems to confirm it in another

Can’t import Numpy in Python

I’m trying to write some code that uses Numpy. However, I can’t import it: I tried the suggestions in this question: and I searched for files named numpy in that path: But nothing came up. So… Are there any other places in which Python modules are commonly installed? How can I install numpy …