Questions tagged [python-import]

1

votes
1

answer
26

Views

Importing a file in python

I tried to import the file only using import I searched the problem and found out it happened because the file isn't in the same working directory as my current file, didn't quite understand that(I am a beginner). So I tried using this: But still I get this error No module named printer1. Here is t...
Programmingfreak
1

votes
0

answer
178

Views

Import of package works in IPython shell but not in Jupyter notebook

I think this question is probably closely related to another one I had, but I'm not sure what the best general-purpose answer is. On my laptop, if I log into the IPython shell, I can execute In [1]: import matplotlib without error. But if I try to do the same thing in a Jupyter notebook, I get the f...
dbliss
1

votes
2

answer
60

Views

How to write a file then import it

I need to write some variables to a file then import it. Whenever I try to run it, though, the console says that the variable doesn't exist. file_writer.py: target = open('save.py', 'w') target.write('x = 2') from save import * print(x) save.py: x = 2 save.py was empty before running file_writer.py.
Card Wallets
1

votes
1

answer
56

Views

python - importing module from within a module

I have this file pluralizer.py containing functions and a class which use the re module: from re import * def pluralize(noun, funcs): for matches_rule, apply_rule in funcs: if matches_rule(noun): return apply_rule(noun) raise ValueError('no matching rule for {0}'.format(noun)) def build_match_and_a...
P. Prunesquallor
1

votes
0

answer
264

Views

How to bundle a python script that imports zerorpc with pyinstaller?

I have the following script called api.py that I'd like to turn into a python app using pyinstaller. The below function works when I run it out of sublime text but when I try to convert it into an unix executable application using pyinstaller, the app does not work. Pyinstaller works only if I dont...
Chris
1

votes
1

answer
581

Views

Import .RTF file to Python

import sys import os.path from pyth.plugins.rtf15.reader import Rtf15Reader from pyth.plugins.xhtml.writer import XHTMLWriter if len(sys.argv) > 1: filename = sys.argv[1] else: filename = os.path.normpath(os.path.join( os.path.dirname(__file__), 'HW1_TRPL_Stranks.rtf')) doc = Rtf15Reader.read(open(...
Melissa Nguyen
1

votes
1

answer
27

Views

error when importing a file from parent dir (because of an another import from the imported file)

I have a project that looks like this: MyProject ├── config.py ├── web.conf ├── Services │ ├── check_db.py check_db.py looks like this: import sys # add parent dir to sys.path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) fr...
Nitzan Cohen
1

votes
0

answer
79

Views

Relative import

I'm trying to make a dynamic relative import in Python but i'm not sure how to do it. My project is organized like this : . ├── __init__.py ├── requests.py └── serializers.py and I need to do the equivalent of from .serializers import Serializer. I tried multiple time with __import...
Steve
1

votes
1

answer
380

Views

ImportError: no module named 'umqtt.MQTTClient' but file with class exists

I installed MicroPython v1.9.3-8 on my ESP8266 board. Here is the beginning of my main.py file: from machine import Pin led = Pin(2, Pin.OUT, value=1) #---MQTT Sending--- from time import sleep_ms from ubinascii import hexlify from machine import unique_id #import socket from umqtt import MQTTClient...
Fabian
1

votes
1

answer
74

Views

Flask Socket.Io: Persistence of initialized socketio after import

So I have the following websocket server api: //x.py ...... import y app = Flask(__name__) app.config['SECRET_KEY'] = 'secret!' socketio = SocketIO(app) @socketio.on('connected', namespace='/getDefects') def connected(): y.set_client_sid(request.sid) y.set_socketio(socketio) @socketio.on('disconnect...
Alex
1

votes
3

answer
209

Views

Can't get python to import nba_py that's in a different folder

I am using Python2.7 and Google App Engine for this project. I am a huge NBA fan and I want to use nba_py api to retrieve additional information to be display on my website but can't seem to import it correctly. I am trying to import it inside my blogfront.py but when I refresh the browser I get an...
Vincent
1

votes
0

answer
68

Views

Does a python dynamic import of module generates .pyc?

I would like to have dotted name strings that I can evaluate. Those dotted names could point to functions from new files the project do not know about (to quickly add a new functionality to the project without being part of the development team). Right now, I resolve and compile the dotted names usi...
David G.
1

votes
0

answer
94

Views

importing lxml on Intellij throws “no such module,” despite successful pip install

I posted this detailing my problem with installing python modules through Intellij, and the answer I accepted there (running \venv\Scipts\activate to activate my virtual environment, and then using pip install module_name) initially worked. However, it seems I have run into another snag with importi...
lmotl3
1

votes
0

answer
47

Views

How can I import a module from a parent directory?

I have the following directory structure for my Python project: lib __init__.py tasks.py api(directory) __init__.py app.py Now, I want to import the tasks module into app.py. If I just type import tasks it magically works in Pycharm, but when executed via bash I get an error message saying 'No modu...
Gasp0de
1

votes
3

answer
249

Views

How can I make a python file runnable as a script and importable as a package?

I'm still trying to get a hang of python 3 and I'm running into an issue where I can either run a .py file as a script or import it as a module, but not both. Directory Structure test/ __init__.py test.py subwayclock/ __init__.py subwayclock.py build/ gen/ __init__.py gtfs_realtime_pb2.py nyct_subw...
Willipedia
1

votes
1

answer
926

Views

How install utils on colab?

How manually install util on google colab? !pip install web.py==0.40.dev0 import utils Error --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) in () 20 import torch.backends.cudnn 21 get_ipython().s...
Nastya
1

votes
0

answer
202

Views

Using pyedflib to write csv to EDF+

Wanted to know is it possible to just directly read in data from csv file and print everything into a EDF file using PYEDFLIB? The biggest challenge is that PYEDFLIB code on their website doesnt support large Data Link for reference about pyedflib http://pyedflib.readthedocs.io/en/latest/
jason van
1

votes
0

answer
164

Views

Import opencv-python single modules

I'm trying to create a python app that uses opencv as backend, the problem arise when i try to export the application using pyinstaller, in fact, even though i use very few functions of cv2: from cv2 import normalize, cvtColor, applyColorMap, imread, NORM_MINMAX, COLORMAP_JET, COLOR_BGR2RGB everytim...
Luca
1

votes
1

answer
108

Views

Importing everything from parent folder as a module?

My project is structured like this right now: Game |__init__.py |Breakout.py |Ball.py |Pad.py |Shared - |__init__.py |GameConstants.py The __init__.py file in the Game folder has the following text: from Game.Ball import Ball from Game.Pad import Pad What I am trying to do, is importing this parent...
StereotypicalCat
1

votes
0

answer
40

Views

How to modify a few lines of Imported Python Library without editing the Library file?

I need to modify one line of an extremely nested python file in an imported library. I needed to handle 1 error exception not covered by the library, so I made a class that inherits the error throwing class (and adds a try/except block). Now I just need to swap my new class for the old one, but I'm...
jonbon
1

votes
0

answer
28

Views

Cannot import matplotlib anymore

I have been using matplotlib with python for a while now. However, when I loaded Spyder up today, I now have this error. Any ideas? ImportError: cannot import name 'dragon4_positional'
Kieran Montgomery
1

votes
0

answer
94

Views

Sudden module imports issues

I've encountered one peculiar issue I just can't understand. I've been working on a code in PyCharm, using Python 3.6 (Windows 10) and I've imported few modules for that objective like so: import requests from bs4 import BeautifulSoup import time import lxml For few days now I've been coding having...
Alon
1

votes
0

answer
607

Views

Plotly: ImportError: cannot import name 'exceptions'

im using Python 3.6.4 in the Anaconda 3 built and for some reason I am no longer able to import Plotly, even-though I just used it hours before. When running import plotly, I get the following error message: import plotly Traceback (most recent call last): File '', line 1, in import plotly File 'C...
Jan Felix
1

votes
0

answer
100

Views

Cannot import Xgboost package in PyCharm (Jupyter) after installation

I am using Pycharm (2017.3.5) as my IDE for Python (3.6) and I integrated Jupyter notebook for development. Untill now, I had no problems with instaling new packages and I did it using Pycharm. Today I am struggling with machine learning library called xgboost. Firstly, the installation error was...
1

votes
2

answer
296

Views

importing python modules into another directory

I have a ROS package that I am working with and I am trying to import a python module from another directory in the same package. My file structure is the follow: package/ src/ __init__.py lab03/ map_helper.py __init__.py lab04/ foo.py __init__.py I want to use helper.py in foo.py foo.py from src.la...
user1376339
1

votes
0

answer
45

Views

Importing your R module in python scripts

Let say I have script calc.R with a function add. add
Yash
1

votes
1

answer
154

Views

ImportError: cannot import name MainClass

society. I'm trying to understand the OOP programming and I'm facing some issues and asking for help. Here the example: I'm trying to create all objects under one class and then I want to inherit from this class. test_class/baseclass.py from test_class.first_class import FirstClass from test_class.s...
Nikolas Miller
1

votes
0

answer
101

Views

ModuleNotFoundError: No module named 'utils' when importing indirectly from a sub package

I have the folder structure below: further down, in the same package as 'account_test.py' I have utils.py that is imported in account_test.py using the following command: from utils import account_tester This works fine when I call account_test directly. However, when I try to import account_test in...
Jorjani
1

votes
0

answer
43

Views

Python can't find self-written module

I'm writing a python module and want to install it. The structure is as follows: look-up ├── look-up │ ├── utilities │ │ ├── __init__.py │ │ ├── validator.py │ └── __init__.py ├── README.md ├── requirements.txt ├── setu...
Fabian Hafner
1

votes
1

answer
242

Views

Error “Attempted relative import” on Sphinx-doc

I tried to use the autodocumentation of Sphinx-doc. I want to fix the following problem. At the moment, no solutions from StackOverflow worked. Is it due to the structure of my project or the way I chose to import my modules ? Given structure of files : project |_ src | |_ pre_processing | |...
floriandaniel
1

votes
1

answer
149

Views

Python: import foo.bar as bar vs from foo import bar

Given that foo.bar is a module, what is the difference between import foo.bar as bar and from foo import bar I'm particularly interested in what lazy importing of modules does to this. Note: This is not a duplicate of this question.
John Oxley
1

votes
1

answer
1.1k

Views

ImportError: No module named 'helper'

My file layout is C:\Fourier-Recovery C:\Fourier-Recovery\cascadenet\ C:\Fourier-Recovery\main_2d.py C:\Fourier-Recovery\cascadenet\network\ C:\Fourier-Recovery\cascadenet\network\layers\ C:\Fourier-Recovery\cascadenet\network\model.py C:\Fourier-Recovery\cascadenet\network\layers\helper.py This la...
Nick X Tsui
1

votes
0

answer
37

Views

Ethics for obtaining a “fanatic” badge using the apscheduler and webbrowser module

So basically i have written a small python script that will automatically visit stackoverflow every day in the event that i am away for whatever reason or forget to visit the site. As much as i enjoy using this site on a daily basis, on several occasions i've reached over 50-60 consecutive days but...
1

votes
1

answer
47

Views

How do import into another folder without __init__?

How do i import Core/Requests into my Asynchronous ? I have tried with sys.path and os.path and still cannot import from there.
Dwi Mulia
1

votes
1

answer
74

Views

Importing local modules in python v. IPython

I've found that IPython and python handle the loading of local modules differently and I wonder if someone could explain why this happens. Suppose that my project is structured as: top_level/ src/ a.py b.py __init__.py The contents of b.py are: from src.a import foo foo() and then a.py has a functio...
webelo
1

votes
0

answer
931

Views

Error import whitenoise

I'm trying to deploy my website in pythonanywhere.com following djangoGirls tutorial. When I run my website, It give me this error: Error running WSGI application ImportError: No module named 'whitenoise' File '/var/www/cryptoassistant_pythonanywhere_com_wsgi.py', line 7, in module> from whitenoise...
XBoss
1

votes
0

answer
609

Views

Can not import Theano

I have cloned theano from the github and installed it via python setup.py install but I've got the following error when trying to import it: import theano.tensor as T Problem occurred during compilation with the command line below: 'C:\MinGW\bin\g++.exe' -shared -g -DNPY_NO_DEPRECATED_API=NPY_1_7_AP...
mikha koltjia
1

votes
0

answer
84

Views

Python ValueError: attempted relative import beyond top-level package

I am trying to make my code Python code run, however, I am running into import errors (shown below). I have looked up some possible solutions and no luck after trying them out. My directory level is fairly simple. Python pkgA __init__.py verify.py console.py I used to be able to run console.py and...
kkmoslehpour
1

votes
0

answer
91

Views

Scipy function not recognized (expit)

I wanted to use the expit-function from scipy in VSCode. I imported scipy.special, but everytime I want to use expit I get the following error: '[pylint] E1101:Module 'scipy.special' has no 'expit' member' Other scipy.special functions like scipy.special.airy work, however. I'm using python 3.6.5 an...
user7948346
1

votes
1

answer
40

Views

Taking an input from python file to another

I made a file that turns to other files and run their scripts consecutively. Most of these files have a common parameter which is an input. When I import it, it (of course) requests for input. I wish to avoid re-input of something. Example: MainFile.py: import Base_params import Liner Base_params.py...
Tak

View additional questions