python-import Questions

17

Solved

Imagine this directory structure: app/ __init__.py sub1/ __init__.py mod1.py sub2/ __init__.py mod2.py I'm coding mod1, and I need to import something from mod2. How should I do it? I tried...
Thinner asked 16/9, 2008 at 14:24

22

Solved

Could someone provide me with a good way of importing a whole directory of modules? I have a structure like this: /Foo bar.py spam.py eggs.py I tried just converting it to a package by adding...
Zayin asked 29/6, 2009 at 9:38

7

Solved

I am running an Ubuntu virtual machine with, Python 3.6.1, Anaconda 4.4.0 (64-bit). I am trying to run the code on this website. When I try to use import cv2.aruco I get: >>> import ...
Predisposition asked 31/8, 2017 at 2:35

6

As far as I know, Python has 3 ways of finding out what operating system is running on: os.name sys.platform platform.system() Knowing this information is often useful in conditional imports, o...
Esteban asked 29/12, 2010 at 10:1

12

Solved

I am very new to PyDev and Python, though I have used Eclipse for Java plenty. I am trying to work through some of the Dive Into Python examples and this feels like an extremely trivial problem tha...
Especial asked 7/1, 2011 at 23:55

3

Solved

When I try to import the module illustris_python I get the error ImportError: No module named 'util' The module util is in the directory below the module snapshot.py that needs it, so I am confus...
Nashom asked 30/4, 2015 at 1:24

1

According to the documentation for unittest.TestLoader.discover: discover(start_dir, pattern=’test*.py’, top_level_dir=None) ... All test modules must be importable from the top level of the ...
Sileas asked 24/9, 2017 at 12:22

11

Solved

I want to inherit from a class in a file that lies in a directory above the current one. Is it possible to relatively import that file?
Zeist asked 28/6, 2009 at 4:56

6

I can't figure out how to be able to package this via py2exe now: I am running the command: python setup2.py py2exe via python 2.7.5 and matplotlib 1.3.0 and py2exe 0.6.9 and 0.6.10dev This wo...
Residence asked 3/9, 2013 at 15:46

2

I have a program (like a macro) that runs within a parent program and imports an API module from that program (lets call it foo). The problem is that that module only exists within that program, so...
Featherweight asked 14/5, 2019 at 16:10

7

Solved

Is it possible to import a module with some parameter in python ? All I mean by parameter is that there exists a variable in the module which is not initialized in that module, still I am using tha...
Airtoair asked 5/6, 2014 at 7:23

4

I was checking the version of OpenCV installed previously in a system. I tried to check using from cv2 import __version__ Its gave me the following error No module named cv2 When I tried im...
Spring asked 19/10, 2017 at 19:40

12

Solved

In Python, is there an analogue of the C preprocessor statement such as?: #define MY_CONSTANT 50 Also, I have a large list of constants I'd like to import to several classes. Is there an analogue...
Aguila asked 14/6, 2011 at 12:17

1

Solved

I am trying to build a Python package, that contains sub-modules and sub-packages ("libraries"). I was looking everywhere for the right way to do it, but amazingly I find it very complica...
Stoichiometry asked 1/1, 2023 at 17:21

9

I have the following package (and working directory): WorkingDirectory-- |--MyPackage-- | |--__init__.py | |--module1.py | |--module2.py | |--notebook.ipynb In __init__.py, I have: import m...

2

Solved

PyCharm shows me that imp is deprecated so I wonder if there any analogue of imp.new_module for importlib.
Goldwin asked 24/8, 2015 at 6:26

4

Solved

In a few of my beginner projects this strange red line underscoring one or more of my imports keeps appearing almost randomly and I can't figure out why. As the module is working perfectly fine it ...
Hypolimnion asked 16/9, 2022 at 20:12

12

Solved

I have a Python program I'm building that can be run in either of 2 ways: the first is to call python main.py which prompts the user for input in a friendly manner and then runs the user input thro...
Protege asked 29/6, 2011 at 16:11

5

When I tried installing Flask I got this error: ImportError: No module named packaging.version
Underneath asked 16/2, 2017 at 23:8

7

Solved

I am using django and I have a file named models.admin.py and I want to do the following idea in models.py: from "models.admin" import * however, I get a syntax error for having double quotes. B...
Corinacorine asked 1/12, 2009 at 18:53

7

Solved

Why doesn't Python allow modules to have a __call__ method? (Beyond the obvious that it wouldn't be easy to import directly.) Specifically, why doesn't using a(b) syntax find the __call__ attribute...
Upanchor asked 29/6, 2009 at 22:1

3

Solved

I meet a similar problem which can be simplified as following: For example I have a file structure as following: ----folder ---- main.py ---- math.py I define a function in math.py and I want...
Charactery asked 9/2, 2019 at 0:31

9

import pyautogui print("hello") After running this I am presented with the following: C:\Users\Darkm\Anaconda3\envs\PythonChallenges\python.exe C:/Users/Darkm/PycharmProjects/PythonChallenges/A...
Dieball asked 16/11, 2019 at 4:10

4

Solved

I am making a package, and the modules within this package have code inside if __name__=='__main__': blocks for testing purposes. But my attempts to use relative imports in these modules causes err...

2

Solved

I create a package connecting to other libraries (livelossplot). It has a lot of optional dependencies (deep learning frameworks), and I don't want to force people to install them. Right now I use...
Overelaborate asked 28/12, 2018 at 12:38

© 2022 - 2024 — McMap. All rights reserved.