python-import

How to suppress ImportWarning in a python unittest script

拈花ヽ惹草 提交于 2019-12-22 04:53:55
问题 I am currently running a unittest script which successfully passes the various specified test with a nagging ImportWarning message in the console: ...../lib/python3.6/importlib/_bootstrap.py:219: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__ return f(*args, **kwds) .... ---------------------------------------------------------------------- Ran 7 tests in 1.950s OK The script is run with this main function: if __name__ == '__main__':

Python: is the current directory automatically included in path?

 ̄綄美尐妖づ 提交于 2019-12-22 03:52:58
问题 Python 3.4: From reading some other SO questions it seems that if a moduleName.py file is outside of your current directory, if you want to import it you must add it to the path with sys.path.insert(0, '/path/to/application/app/folder') , otherwise an import moduelName statement results in this error: ImportError: No module named moduleName Does this imply that python automatically adds all other .py files in the same directory to the path? What's going on underneath the surface that allows

import error in python

梦想与她 提交于 2019-12-22 03:36:08
问题 I get the following error Traceback (most recent call last): File "myemail.py", line 1, in <module> import smtplib File "/usr/lib/python2.6/smtplib.py", line 46, in <module> import email.utils File "/home/nikhil/Desktop/bujji/email.py", line 2, in <module> ImportError: No module named MIMEMultipart when i run the code example I tried to google out the error but nothing worked. 回答1: You've stomped on the email package in the stdlib by naming a script email.py . Rename it. 回答2: Don't have

Python Module Imports - Explicit vs Implicit Relative Imports

若如初见. 提交于 2019-12-22 03:17:11
问题 Last night, when working on my mac, I set up some module imports in my __init__.py 's from MongoProvider import MongoProvider from Settings import Settings etc. I'm unsure of what version of Python is on that machine. I'll edit the question later with that info once I have it. Today, working on a different machine, which is Windows and using Python 3.3.3, my module imports were breaking. By adding an explicit relative import (adding a leading dot), I was able to fix the issue. from

how to import module from other directory in python? [duplicate]

不问归期 提交于 2019-12-22 00:28:12
问题 This question already has answers here : How to do relative imports in Python? (14 answers) Closed 5 years ago . This is my directory tree Game/ a/ 1.py ... b/ 2.py In 2.py I want import function display from 1.py. First I keep both file in same folder there is no problem.But how to import from other location? 回答1: try using imp: import imp foo = imp.load_source('filename', 'File\Directory\filename.py') this is just like importing normally now you can use the file use imported you then use

ImportError: No module named lib. Unable to import pandas, numpy, scipy, matplotlib

心不动则不痛 提交于 2019-12-22 00:05:07
问题 I recently updated a number of packages and my version of EPD Canopy (to1.4.1.1975) and now I'm unable to import pandas , numpy , scipy or matplotlib . I get the ImportError below. I've also tried importing from the command prompt but I can the same error. pandas - 0.14.0-1 numpy - 1.8.0-2 scipy - 0.14.0-1 matplotlib - 1.3.1-8 Does anybody have any suggestions as to how I could fix this? From this Stackoverflow question it seems like I might need to change/move something to a different

How to use sys.path_hooks for customized loading of modules?

夙愿已清 提交于 2019-12-21 17:58:07
问题 I hope the following question is not too long. But otherwise I cannot explain by problem and what I want: Learned from How to use importlib to import modules from arbitrary sources? (my question of yesterday) I have written a specfic loader for a new file type (.xxx). (In fact the xxx is an encrypted version of a pyc to protect code from being stolen). I would like just to add an import hook for the new file type "xxx" without affecting the other types (.py, .pyc, .pyd) in any way. Now, the

Python import modules in another file

十年热恋 提交于 2019-12-21 17:54:57
问题 I'm currently re-factoring a project (formerly big one file) into several seperate python files, each of which runs a specific part of my application. Eg, GUIthread.py runs the GUI, Computethread.py does some maths, etc etc. Each thread includes the use of functions from imported modules like math , time , numpy , etc etc. I already have a file globalClasses.py containing class definitions for my datatypes etc, which each .py file imports at the start, as per recomendation here: http://effbot

Python imports from subfolders

我怕爱的太早我们不能终老 提交于 2019-12-21 03:42:23
问题 I am attempting to grade some python submissions that are in separate folders for each student. To do this, there is a function, say f() which I want to run. I understand that if my current path is the same as the one where the file is located, I can simply do import filename filename.f() However, are there better ways? For instance, let's say the directory structure is as follows: main.py student/run_this.py I know that if there is a "__init__.py" file in the student folder, I can just type

Why does “import module” and then “from package import module” load the module again?

假如想象 提交于 2019-12-21 03:36:32
问题 I have a package in my PYTHONPATH that looks something like this: package/ __init__.py module.py print 'Loading module' If I'm running Python from the package/ directory (or writing another module in this directory) and type import module it loads module.py and prints out "Loading module" as expected. However, if I then type from package import module it loads module.py and prints "Loading module" again , which I don't expect. What's the rationale for this? Note: I think I understand