python-import

Automatically create requirements.txt

本秂侑毒 提交于 2020-04-30 07:14:09
问题 Sometimes I download the python source code from github and don't know how to install all the dependencies. If there is no requirements.txt file I have to create it by hands. The question is: Given the python source code directory is it possible to create requirements.txt automatically from the import section? 回答1: If you use virtual environment, pip freeze > requirements.txt just fine. IF NOT , pigar will be a good choice for you. By the way, I do not ensure it will work with 2.6. UPDATE :

Automatically create requirements.txt

做~自己de王妃 提交于 2020-04-30 07:13:07
问题 Sometimes I download the python source code from github and don't know how to install all the dependencies. If there is no requirements.txt file I have to create it by hands. The question is: Given the python source code directory is it possible to create requirements.txt automatically from the import section? 回答1: If you use virtual environment, pip freeze > requirements.txt just fine. IF NOT , pigar will be a good choice for you. By the way, I do not ensure it will work with 2.6. UPDATE :

Google-Colaboratory local module ModuleNotFoundError

偶尔善良 提交于 2020-04-18 07:00:30
问题 I have cloned a github repository into google-colab [https://github.com/limbo018/DREAMPlace] and installed the necessary requirements. When I run the main script (!python dreamplace/placer.py) from either the base repo directory or the cmake install directory in jupyter I receive a modulenotfound error. I am able to import the module from a jupyter cell. The placer.py script imports it's parent module (dreamplace), which I have added to the path. I have a feeling colab/jupyter spawns a

pyinstaller Hidden import not found

 ̄綄美尐妖づ 提交于 2020-04-16 05:51:30
问题 I'm using pyinstaller. In my script there is: import toml config = toml.load('config.toml') I compiled my script with: pyinstaller main.py --onefile --clean --name myApp but when I run the executable it gave me: ModuleNotFoundError: No module named 'toml' So I tried this: pyinstaller main.py --hidden-import toml --onefile --clean --name myApp and now pyinstaller says: ERROR: Hidden import 'toml' not found 回答1: Found the answer. If you are using a virtual environment (Like Pipenv, pyenv, venv)

Opening a file from an imported function

六月ゝ 毕业季﹏ 提交于 2020-04-16 03:36:48
问题 I've been "fighting" with absolute and relative paths in Python for a while and I know that there are quite a few questions on this topic, but I couldn't find an answer to my particular problem. Given the following project structure: package/ subpackage1/ moduleX.py moduleY.py subpackage2/ moduleZ.py folder1/ file1.txt I am importing in moduleX.py a function from moduleZ.py which requires information stored in file1.txt to work. I have no problem importing the function from moduleZ.py ,

import module in Class, but NameError when using module in class method

放肆的年华 提交于 2020-04-15 21:45:29
问题 In my python script, I'm trying to import module in class and use the imported module in the class method. class test: import urllib.parse def __init__(self, url): urlComponents = urllib.parse.urlsplit(url) Howerver, when I try to use the test class, such as test("http://test.com") I get the error: NameError: name 'urllib' is not defined Why import statement in class body do not take effect? I use python 3.8.1 in windows 10. 回答1: The import statement performs a name binding, but names inside

How to import class name python

点点圈 提交于 2020-04-14 07:22:10
问题 Here is my python folder structure (it does not have any python package): folder/ script1.py script2.py script1 has: class myclass(object): def __init__(): print("in init") def showReport(): print("in report only function") script2 has: from . import myclass and when I run python -m folder.script2 I get /usr/bin/python: cannot import name myclass How can I import this class so that I can call functions from this class on script2? 回答1: You say you do have a package, but you still have to

How to import class name python

ぐ巨炮叔叔 提交于 2020-04-14 07:22:02
问题 Here is my python folder structure (it does not have any python package): folder/ script1.py script2.py script1 has: class myclass(object): def __init__(): print("in init") def showReport(): print("in report only function") script2 has: from . import myclass and when I run python -m folder.script2 I get /usr/bin/python: cannot import name myclass How can I import this class so that I can call functions from this class on script2? 回答1: You say you do have a package, but you still have to

How to import external scripts in a Airflow DAG with Python?

我只是一个虾纸丫 提交于 2020-03-25 03:40:31
问题 I have the following structure: And I try to import the script inside some files of the inbound_layer like so: import calc However I get the following error message on Airflow web: Any idea? 回答1: I needed insert the following script inside at the top of ren.py : import sys, os from airflow.models import Variable DAGBAGS_DIR = Variable.get('DAGBAGS_DIR') sys.path.append(DAGBAGS_DIR + '/bi/inbound_layer/') This way I make available the current folder packages. 回答2: For airflow DAG, when you

PyCharm not recognizing Django project imports: from my_app.models import thing

徘徊边缘 提交于 2020-03-18 03:22:17
问题 I just started testing out PyCharm on my existing Django project, and it doesn't recognize any imports from apps within my project: in my_app1/models.py : from my_app2.models import thing "Unresolved reference 'my_app2'" Why is this? My project's directory structure matches the recommended layout, and it runs without errors, it's just PyCharm's magic doesn't want to work on it. It seems related to this question: Import app in django project But I can't figure out what I am doing wrong. If I