This question already has answers here: How do I import other Python files? (23 answers) Closed 6 months ago. file.py contains a function named function. How do I import it? The above gives an error: ImportError: No module named ‘file.py’; file is not a package Answer First, import function from f…
Tag: import
I’m not able to import Flask-WTF TextField and BooleanField
I’m using virtualenv to set up a new project. I installed a lot of things using virtualenv pip from the script folder like below: I have no other packages installed in the global python folder. My code looks like this: and other packages are found like sqlalchemy also installed only in the virtual envir…
Relative imports for the billionth time
I’ve been here: http://www.python.org/dev/peps/pep-0328/ http://docs.python.org/2/tutorial/modules.html#packages Python packages: relative imports python relative import example code does not work Relative imports in python 2.5 Relative imports in Python Python: Disabling relative import and plenty of U…
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…
How to ignore Pyflakes errors ‘imported but unused’ in ‘__init__.py’ files?
I split my tests across multiple Python files: I import the tests in the ‘__init__.py’ file: However running Pyflakes on the command-line: outputs the following errors: Answer Add # pyflakes.ignore comment on every line you want to ignore (in your case import statements).
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 …