python-import

What is the PEP8 recommendation for multiple imports from a package?

旧街凉风 提交于 2020-06-15 06:23:11
问题 The PEP8 style guide section on imports seems to be a bit ambiguous. From: https://www.python.org/dev/peps/pep-0008/#imports The first part makes sense: # Imports should usually be on separate lines: # Correct: import os import sys # Wrong: import sys, os But then it goes on to say: # It's okay to say this though: # Correct: from subprocess import Popen, PIPE How should we interpret this? subprocess is a module, so is PEP8 saying it's just OK to import multiple things from a single module on

Why is the import of `*.so` files from ZIP files disallowed in Python?

China☆狼群 提交于 2020-06-12 12:57:13
问题 Why is the import of *.so files from ZIP files disallowed in Python? The documentation (https://docs.python.org/2/library/zipimport.html) is very clear: Any files may be present in the ZIP archive, but only files .py and .py[co] are available for import. ZIP import of dynamic modules (.pyd, .so) is disallowed. But the documentation doesn't name any reason for this strange limitation. Is is because importing from ZIP files is generally discouraged in Python? Or is it because of security

I can't import xml.dom.minidom in PyCharm. What could I Try?

你离开我真会死。 提交于 2020-06-08 19:17:37
问题 I'm trying to import xml.dom.minidom but pycharm doesn't find it, altough it finds xml.entree / xml.parser / xml.sax. The rest of the standart libraries work all fine. The xml file (beispiel.xml) shouldn't be the problem, because it hasn't "xml" in the name. from xml.dom import minidom document = minidom.parse("beispiel.xml") wanted_info = input("Which prduct do you want to see?") product_list = document.getElementsByTagName(wanted_info) for product in product_list: for value in product

I can't import xml.dom.minidom in PyCharm. What could I Try?

♀尐吖头ヾ 提交于 2020-06-08 19:17:08
问题 I'm trying to import xml.dom.minidom but pycharm doesn't find it, altough it finds xml.entree / xml.parser / xml.sax. The rest of the standart libraries work all fine. The xml file (beispiel.xml) shouldn't be the problem, because it hasn't "xml" in the name. from xml.dom import minidom document = minidom.parse("beispiel.xml") wanted_info = input("Which prduct do you want to see?") product_list = document.getElementsByTagName(wanted_info) for product in product_list: for value in product

Paradoxon: silent crash on Python's ctypes.CDLL when importing, but not when running directly - how is this possible?

ε祈祈猫儿з 提交于 2020-05-29 07:56:51
问题 So, being a Linux guy I stumbled into something pretty puzzling on Windows that I just can't explain. I have a project structure analougus to this example: D:\PROJECT | | tolkien.py | __init__.py | \---MiddleEarth | gondor.py | isengrad.c | __init__.py | \---lib isengrad.so Problem: I compile isengrad.c into the shared libary isengrad.so , then load it in gondor.py . My aim is to import gondor.py into tolkien.py . While gondor.py runs flawlessly when it is run directly, when I import it, the

Getting PyCharm to import sklearn

天涯浪子 提交于 2020-05-11 03:59:18
问题 Beginner here. I’m trying to use sklearn in pycharm . When importing sklearn I get an error that reads “Import error: No module named sklearn ” The project interpreter in pycharm is set to 2.7.10 (/anaconda/bin/python.app), which should be the right one. Under default preferenes, project interpreter, I see all of anacondas packages. I've double clicked and installed the packages scikit learn and sklearn . I still receive the “Import error: No module named sklearn” Does anyone know how to

How to import python class file from same directory?

女生的网名这么多〃 提交于 2020-05-09 18:41:25
问题 I have a directory in my Python 3.3 project called /models. from my main.py I simply do a from models import * in my __init__.py : __all__ = ["Engine","EngineModule","Finding","Mapping","Rule","RuleSet"] from models.engine import Engine,EngineModule from models.finding import Finding from models.mapping import Mapping from models.rule import Rule from models.ruleset import RuleSet This works great from my application. I have a model that depends on another model, such that in my engine.py I

ImportError: No module named 'cv2' Python3

非 Y 不嫁゛ 提交于 2020-05-07 12:47:12
问题 I have such a problem (face_det) user@pc:~$ python3 Python 3.5.3 (default, Apr 22 2017, 00:00:00) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'cv2 I don't have it on python2: (face_det) user@pc:~$ python2 Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2 Type

py2app ImportError with watchdog

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-30 09:19:47
问题 I am attempting to use py2app to bundle a small Python app that I've made in Python 2.7 on Mac. My app uses the Watchdog library, which is imported at the top of my main file: from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler When running my program, these import statements work just fine, and the program works as expected. However, after running py2app, launching the bundled application generates the following error: ImportError: No module named

py2app ImportError with watchdog

蹲街弑〆低调 提交于 2020-04-30 09:17:12
问题 I am attempting to use py2app to bundle a small Python app that I've made in Python 2.7 on Mac. My app uses the Watchdog library, which is imported at the top of my main file: from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler When running my program, these import statements work just fine, and the program works as expected. However, after running py2app, launching the bundled application generates the following error: ImportError: No module named