python-import

How to import python file(.py) into a main python file

让人想犯罪 __ 提交于 2020-07-29 13:22:12
问题 is there a way to import multiple python files into a main python file? I have a bunch of py files and each one has to run in the main python file and the data are saved into a json file. This is what I tried and it gave me an error. import light.py as light Error: Traceback (most recent call last): File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked AttributeError: 'module' object has no attribute '__path__' During handling of the above exception, another exception

Python imports when scripts are run from different folder (ancestor)

断了今生、忘了曾经 提交于 2020-06-28 04:56:32
问题 I have a large repository with some fixed structure and I have extended it by some folders and python scripts to add extra functionality to it as a whole. The structure looks as follows: toplevelfolder featureA someModuleA.py __ init __.py featureB someModuleB.py __ init __.py application __ init __.py app.py Now someModuleA.py and someModuleB.py can be invoked via app.py but at the same time also have be able to be invoked directly, however this invocation must come from the toplevelfolder

Import tensorflow module is slow in tensorflow 2

时间秒杀一切 提交于 2020-06-27 07:22:15
问题 Related: Import TensorFlow contrib module is slow in TensorFlow 1.2.1 also: What can cause the TensorFlow import to be so slow? I am using an ssd and importing TensorFlow. I have 4 ghz 8 core pc with 16 gb ram (Processor AMD FX(tm)-8350 Eight-Core Processor, 4000 Mhz, 4 Core(s), 8 Logical Processor(s)). TensorFlow takes 10-12 seconds to import. Is there any way to selectively import parts of TensorFlow? Would a RAM disk help? Is there any more work being done on stuff like this or: Slow to

Python - Import package modules before as well as after setup.py install

社会主义新天地 提交于 2020-06-25 10:15:28
问题 Assume a Python package (e.g., MyPackage ) that consists of several modules (e.g., MyModule1.py and MyModule2.py ) and a set of unittests (e.g., in MyPackage_test.py ). . ├── MyPackage │ ├── __init__.py │ ├── MyModule1.py │ └── MyModule2.py ├── README.md ├── requirements.txt ├── setup.py └── tests └── MyPackage_test.py I would like to import functions of MyModule1.py within the unittests of MyPackage_test.py . Specifically, I would like to import the functions both before as well as after

Python - Import package modules before as well as after setup.py install

故事扮演 提交于 2020-06-25 10:15:00
问题 Assume a Python package (e.g., MyPackage ) that consists of several modules (e.g., MyModule1.py and MyModule2.py ) and a set of unittests (e.g., in MyPackage_test.py ). . ├── MyPackage │ ├── __init__.py │ ├── MyModule1.py │ └── MyModule2.py ├── README.md ├── requirements.txt ├── setup.py └── tests └── MyPackage_test.py I would like to import functions of MyModule1.py within the unittests of MyPackage_test.py . Specifically, I would like to import the functions both before as well as after

Import a library which is in a sibling of the current folder

本秂侑毒 提交于 2020-06-24 12:08:39
问题 With the folder structure lib/ abcd/ __init.py__ lib.py app.py the code from lib.abcd import lib works. But with this file structure: bin/ app.py lib/ abcd/ __init.py__ lib.py the code from ..lib.abcd import lib gives an import error. How to do the import properly when the library is in a sibling of the current folder? (or subfolder of a sibling folder) I know that there might some hack that involves adding lib/ to the PATH, but is there an elegant Pythonic solution? If not, is there a real

Import a library which is in a sibling of the current folder

不羁的心 提交于 2020-06-24 12:06:06
问题 With the folder structure lib/ abcd/ __init.py__ lib.py app.py the code from lib.abcd import lib works. But with this file structure: bin/ app.py lib/ abcd/ __init.py__ lib.py the code from ..lib.abcd import lib gives an import error. How to do the import properly when the library is in a sibling of the current folder? (or subfolder of a sibling folder) I know that there might some hack that involves adding lib/ to the PATH, but is there an elegant Pythonic solution? If not, is there a real

Flask AttributeError: module 'app' has no attribute 'run'

这一生的挚爱 提交于 2020-06-23 06:50:27
问题 My Flask project is structured as follows: my_project │ ├── app │ ├── __init__.py │ ├── api │ ├── static │ └── templates ├── config.py └── run.py app/__init__.py : from flask import Flask app = Flask(__name__) app.config.from_object('config') run.py from app import app app.run( host=app.config.get('HOST', '0.0.0.0'), port=app.config.get('PORT', 5000) ) This worked before, but I'm trying to migrate my project from Python 2 to Python 3, and running python run.py no longer works. I get the

Cannot import keras.initializers

纵饮孤独 提交于 2020-06-18 11:58:05
问题 I have imported all necessary modules from keras into jupyter notebook from keras.preprocessing.text import Tokenizer from keras.preprocessing.sequence import pad_sequences from keras.models import Sequential from keras.layers import Embedding, Dense, Dropout, Reshape, Merge, BatchNormalization, TimeDistributed, Lambda, Activation, LSTM, Flatten, Convolution1D, GRU, MaxPooling1D from keras.regularizers import l2 from keras.callbacks import Callback, ModelCheckpoint, EarlyStopping from keras

ImportError: cannot import name 'FFProbe'

此生再无相见时 提交于 2020-06-16 09:17:11
问题 I can't get the ffprobe package to work in Python 3.6. I installed it using pip, but when I type import ffprobe it says Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python\Python36\lib\site-packages\ffprobe\__init__.py", line 1, in <module> from ffprobe import FFProbe ImportError: cannot import name 'FFProbe' The __init__.py file contains just the single line from ffprobe import FFProbe . sys.path includes 'C:\Python\Python36\lib\site-packages', which is