Questions tagged [python-import]
For questions about importing modules in Python
5,925
questions
0
votes
0
answers
26
views
Python: Import class from args parser [duplicate]
I want to know if it is possible to import a class from the input arguments of argsparser.
What I am doing now is something like this:
parser = argparse.ArgumentParser()
parser.add_argument('-p', dest=...
0
votes
1
answer
33
views
How to import a .slk file in python
I have a .slk file that I couldn't import in python, I used the following code but it doesn't work:
from sylk_parser import SylkParser
parser = SylkParser("fileName.slk")
I got this error:
...
0
votes
0
answers
33
views
Setuptools & Python Packaging
There is a similar question but it does not fit 100% to mine.
I have this project layout:
src/
└── mypackage/
├── __init__.py (empty)
├── a.py
└── mysubpackage1/
├── ...
0
votes
0
answers
17
views
Clear module import cache after executing Python code from zip file
I'm looking for a way to reliably clear the module import cache after loading and executing code from zip files (the zip files with Python code serve as a "plugin").
The current way I'm ...
0
votes
0
answers
18
views
Google Colab not importing jumpy after installing brax
I've tried restarting the runtime and pip installing brax again using this command, "!pip install git+https://github.com/google/brax.git@main", but regardless of how many times I do it, &...
0
votes
0
answers
33
views
importing numpy and got Intel MKL FATAL ERROR: Cannot load libmkl_intel_thread.1.dylib
I am using MacBook Pro M1 on Sonoma 14.1 (23B74)
The extensions I am using on VSCode are:
Python v2023.20.0
and
Pylance v2023.11.10
I ran this python code on VSCode
import numpy as np
x = np.array([1, ...
0
votes
0
answers
31
views
How to call a python function from another Python file which I imported in my robot file? [duplicate]
My Folder Structure is as below
|
|--Folder1
| |
| |--helperAA.py
|
|--Folder2
|
|---Folder3
|
|---Folder4
|
|---Folder5
...
0
votes
0
answers
9
views
Blender Python Package Cannot be Resolved in VSCode
I'm trying to get Blender's python library (bpy) working with VSCode but for some reason despite having the correct interpreter selected, VSCode cannot resolve the package. What's strange is that ...
-1
votes
0
answers
15
views
New to Python, I don't understand why my "from models.models" isn't working. It says "Import could not be resolved"
I'm working on creating a database project and have been familiarizing myself with imports and the language itself. I am on windows 11, downloaded Python3 as the interpreter, and I am using VSCode. ...
0
votes
1
answer
37
views
how to import python modules in folders to list
I'm trying to get a list of all the mods that I have for a fun project I'm working on but I can't figure out how to get it to work I have already researched this for a couple of hours and couldn't ...
0
votes
0
answers
24
views
Unittests - Python - Being in a subfolder, how can i import from another subfolder at the same level?
Under my GitHub repository, imagine I have 2 subfolders, one holds my lambda code (subfolderA), and the other holds my unittest (subfolderB) that I want to run against that lambda code - structure ...
1
vote
0
answers
104
views
How to use the Python serialization library (serial) alongside the serial port access library (pyserial)
I want to use the serial and the pyserial library in the same Python script. The problem is that both libraries are imported using the same statement:
import serial
There are many questions regarding ...
0
votes
0
answers
18
views
Can't I import the same library in the same folder using venv?
I like to develop using Jupyter notebooks on VScode and I just started to use Poetry. I had a tree folder like this:
│───code
├───project_lambda
│ │ dev.ipynb
│ │ lambda_function.py
│ │ ...
0
votes
2
answers
140
views
Unable to install packages with pip in VS code
I am trying to install Flask with the following command:
pip install flask
But pip returns:
Requirement already satisfied: flask in /home/john/anaconda3/lib/python3.11/site-packages (3.0.0)
...
0
votes
0
answers
29
views
importlib.import_module loading the wrong module in custom plugin system
I'm trying to implement a plugin system in Python.
Each plugin exposes exactly the same function and I want to call one or another, for instance with a simple Id.
For instance, the plugins can be ...
0
votes
1
answer
37
views
import seaborn displays error: Import "seaborn" could not be resolved Pylance (reportMissingImports)
I am new prgrammer, using VScode and Ubuntu for python. I have installed seaborn from Ubuntu by "pip install seabron". But when I am running from VSCode yellow marked warning displays "...
0
votes
1
answer
41
views
python importlib.import_module into current scope
I'm following in a long line of people struggling with importlib (1, 2) (I have also read the docs).
I want to import all the elements in a list into the current scope as if I had done import ...
0
votes
1
answer
66
views
Pytest atomic test succeed but fail when running with other tests
I want to test a import in a module module.py based on a variable environnement. To do that I use a fixture changing the var env and I test that in test_module.py.
If I run pytest test/test_module.py ...
0
votes
1
answer
57
views
How to solve theano - circular import problem in python?
I try to run some code from 2019 in my jupyternotebook. I have error that I don't know how to solve:
----> 8 import theano.tensor as T
...
File ~/my-jupyter-env/lib/python3.11/site-packages/...
-2
votes
0
answers
16
views
Resolving local package imports in Python
My repo directory structure is as follows (from $ tree):
.
├── src
│ ├── __init__.py
│ └── stuff.py
├── tests
│ ├── __init__.py
│ ├── test_stuff.py
│ ├── test_utils_constants.py
│ └── ...
-1
votes
0
answers
33
views
python turtle : how to make a turtle object that can shoot bullets automatically?
how to make a turtle object that can shoot bullets automatically and under control? please help me. i have tried this code and the game is crashing(Enemy aircraft fired bullets continuously without ...
0
votes
0
answers
15
views
How do I solve [WinError 193] %1 is not a valid Win32 application installing torchrec?
I am trying to install the the torchrec library from the Pytorch universe. I do not get any error message installing it via pip, however when I am trying to import the torchrec package I get the error ...
-1
votes
1
answer
36
views
Import script from another folder without knowing the precise path
I have two files F1.py and F2.py with the following structure:
|-----F2.py
|
|-----Folder2
|
[...]-----Folder1
|
...
0
votes
0
answers
22
views
Activate flag only for specific imported module in Python
I am trying to follow the instructions shown here: https://docs.python.org/3.10/whatsnew/3.0.html#porting-to-python-3-0
Specifically, "Turn on the -3 command line switch".
It is regarding ...
0
votes
0
answers
13
views
No module - importing pyotp
ModuleNotFoundError: No module named 'pyotp'
While doing
I am getting the above error.
Please note I already installed pyotp 2.9.0
I can see that in the pip list
Even I can import pandas without ...
0
votes
1
answer
63
views
How can I import a package from within the same package?
I got this python package here called "pgk", and I'd like to import it from a module within itself:
pkg/
__init__.py
test.py
__init__.py is empty
test.py:
When trying from .. ...
0
votes
0
answers
25
views
Can anyone explain when two imports of the same Python module can result in two different module objects?
Last year, I wrote the following three modules in Python 3.7.2:
# my_module.py
my_counter = 0 ...
-1
votes
0
answers
25
views
Importing an arbitrary file that I python like
I'm trying to create a tool, and want to implement it with python.
I only care about using this with a modern python 3 system.
I'd like to do this with the standard python libraries no extra modules.
...
-1
votes
1
answer
36
views
Inconsistent Behavior of a List When Accessed Across Different Python Modules
I'm experiencing a peculiar issue with a list in Python that seems to behave inconsistently when accessed across different modules. I have three Python files: main.py, mymodule.py, and myothermodule....
0
votes
0
answers
15
views
Python, override initial import dynamically using importlib not working
I have a python file script_00.py, where I import some module at the beginning:
from some_path import Core
However, based on the value of a variable, I might have to override this and load an ...
-1
votes
0
answers
33
views
Solve imported but unused in "middle" module [duplicate]
I don't know if this is the correct approach, but I have a module which imports something from another module with the sole purpose of having it available for the users of that module.
Specifically it ...
0
votes
0
answers
44
views
Code doesn't work after importing another package
I'm currently working in PyCharm version 11.0.11 with Python 3.9, and I'm using Manim Community version 0.17.3.
In my project, the only library I had imported was Manim:
from manim import *
The code ...
0
votes
0
answers
39
views
can each import create a separate object?
Imagine a library of classes supporting different input or output formats. Applications may switch between those formats. I'm using different languages only as an example.
A straightforward way to set ...
3
votes
2
answers
82
views
What causes an ImportError to report "(unknown location)"?
Looking at this question, there is this import error:
>>> from flask_security import login_user
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
0
votes
1
answer
72
views
Flask app running with Flask but not Gunicorn
I created a Flask app for some of my projects. There is a main app.py in the ~/flasksvr directory, and the folder structure looks a bit like this:
flasksvr/
> __init__.py (empty)
> app.py (main ...
0
votes
1
answer
16
views
Unit Test Imported Modules when A Global Function Call will Fail
I am trying to mock a session created in a test by an import. I have two files:
/lib/module.py
import boto3
session = boto3.session()
/tests/test.py
from lib.module import test_func
test_function():
...
0
votes
0
answers
27
views
How to resolve No module named 'PIL' error message
I acknowledge that this issue is common and widely reported. However, all solutions listed did not resolve the current issue I am facing.
I have downloaded Pillow using pip. I am using python, not ...
0
votes
1
answer
82
views
ModuleNotFoundError when importing my own python module
so the problem is that when I try to import something from the module I created, I run into ModuleNotFoundError: No module named '<my_module>'.
My project structure is just like this one:
├── ...
0
votes
0
answers
32
views
How properly set up internal imports in Python package?
I am developing a Python 3 package (say "Project1"), which I want to use in another Python project (say "Project2"). The structure of the Project1 is, briefly, like this:
/...
0
votes
2
answers
73
views
Can't import my own module in my test file
I have the following project structure :
.
├── README.md
├── document_processing
│ ├── Config.py
│ ├── DocumentParser.py
│ ├── FileChecker.py
│ └── __init__.py
├── indexing.py
└── tests
├──...
0
votes
1
answer
33
views
Unable to import modules from a directory
I have created a file main.py which imports out_handler.py which imports style_generator.py but every time I try to implement it with import I get this error
Traceback (most recent call last):
File ...
0
votes
2
answers
41
views
Getting "ImportError: attempted relative import beyond top-level package" when loading Cogs
I've bee looking up questions with the same issues for a long time, but none seem to solve my issue.
I'm currently trying to load the Cogs for my bot, but whenever I do so, I get the error: "...
1
vote
0
answers
29
views
Programatically import all files in a folder to a list [duplicate]
I'm somewhat new to Python, so there probably are many mistakes in my approach. I've been searching for this for a while but was unable to find or implement a solution. Maybe it's due to how I'm ...
0
votes
1
answer
60
views
How to relative import a module from another directory in the top directory (python)?
I have a project structured the following way:
project/
main.py
package1/
module1.py
module2.py
subpackage1/
module4.py
package2/
module3.py
#...
0
votes
0
answers
44
views
correct import path for setuptools
I'm installing a project with setuptools but couldn't get the import path correct.
The project is simple:
.
├── setup.py
└── src
├── europe
│ ├── germany.py
│ └── __init__.py
├── ...
1
vote
2
answers
108
views
Lazy import from a module (a.k.a. lazy evaluation of variable)
Lazy imports in Python have been long discussed and some proposals (for example the PEP609 - Lazy Imports) have been made to make it a built-in (optional) feature in the future.
I am developing a CLI ...
0
votes
3
answers
205
views
Python sibling relative import error: 'no known parent package'
I want to import a module from a subpackage so I went here Relative importing modules from parent folder subfolder and since it was not working I read all the literature here on stack and found a ...
0
votes
2
answers
75
views
Is there any meaningful difference between "import module; import module as blah" and "import module; blah=module"?
This question is merely for my understanding of Python modules.
I am curious if there is any meaningful difference, other than readability, between these two lines:
import module ; import module as ...
0
votes
0
answers
3
views
ImportError: cannot import name 'ImpliciteSourceTerm' from 'fipy'
I want to solve the Advection-Diffusion equation with a source term in fipy. For my source term, I consider an input coefficient (inputCoeff) and an output coefficient (outputCoeff). When invoking the ...
0
votes
2
answers
34
views
Django settings.py can't import my local module
My Django tree looks like this
git/src
├── myproject
│ ├── settings.py
│ ├── mysharedlib.py
│ └── urls.py
└── www
├── myotherlib.py
├── urls.py
└── views.py
It works except that in ...