Top "Python-import" questions

For questions about importing modules in Python

Importing a long list of constants to a Python file

In Python, is there an analogue of the C preprocessor statement such as?: #define MY_CONSTANT 50 Also, I have a …

python constants python-import
Should I use `import os.path` or `import os`?

According to the official documentation, os.path is a module. Thus, what is the preferred way of importing it? # Should …

python coding-style python-import
In Python, what happens when you import inside of a function?

What are the pros and cons of importing a Python module and/or function inside of a function, with respect …

python python-import
ImportError: libSM.so.6: cannot open shared object file: No such file or directory

When trying to import OpenCV, using import cv2 I get the following error: /usr/local/lib/python2.7/dist-packages/cv2/__init__.…

python opencv python-import importerror python-module
Error importing Seaborn module in Python

I am trying to import seaborn into python (using 2.7) using the following code: import matplotlib.pyplot as plt import seaborn …

python-2.7 python-import seaborn
PYTHONPATH vs. sys.path

Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a …

python python-import pythonpath sys.path
What does from __future__ import absolute_import actually do?

I have answered a question regarding absolute imports in Python, which I thought I understood based on reading the Python 2.5 …

python python-2.7 python-import python-2.5
Importing packages in Python

I am probably missing something obvious but anyway: When you import a package like os in python, you can use …

python python-import
ImportError: No module named mock

So I am trying to use unittest.mock to mock some of my methods in my unit tests. I do: …

python python-2.7 python-import importerror
Flask - ImportError: No module named app

First I created __init__.py from flask import Flask app = Flask(__name__) Then in a separate file, in the same …

python python-import