当一个foo
人在源目录中尝试导入模块时,会得到一个相当混乱的ImportError
消息:ImportError: No module named foo
.
如何轻松捕获此案例并返回更多信息,例如"请不要从源目录加载模块foo"?
有了__init__.py
,我会开始:
try:
from _foo import *
except ImportError:
## check whether in the source directory...
Run Code Online (Sandbox Code Playgroud)
所以我想区分a的不同原因ImportError
(例如,因为一个名为的模块foo
根本没有安装),并检测它setup.py
位于当前目录中的情况.这样做的优雅方式是什么?
我正在尝试将Dagger实现为IntelliJ项目中的依赖注入器,但我的代码失败了:
import javax.inject.Inject;
Run Code Online (Sandbox Code Playgroud)
Intellij正在寻找' javax
'包,但不是' inject
'包,所以它失败了.
我是Android的新手,所以我很抱歉,如果这是一个没脑子,但任何人都可以告诉我为什么没有找到注入包?
无法解析符号TabLayout?如何清除此错误?请帮我.我已经导入了import android.support.design.widget.TabLayout;
android importerror android-fragments android-studio android-tablayout
我偶然发现了绝对导入的问题。该存储库可在此处公开:https ://github.com/repetitioestmaterstudiorum/ts-boiler
当我尝试导入具有绝对路径(相对于项目目录)的文件然后执行时npm run dev
,否则npm run ts-node src/index.ts
出现以下错误:
Error: Cannot find module '/src/constants'
Require stack:
- /Users/<my-username>/<some-path>/ts-boiler/src/index.ts
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/<my-username>/<some-path>/ts-boiler/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/<my-username>/<some-path>/ts-boiler/src/index.ts:1:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module.m._compile (/Users/<my-username>/<some-path>/ts-boiler/node_modules/ts-node/src/index.ts:1597:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .ts] (/Users/<my-username>/<some-path>/ts-boiler/node_modules/ts-node/src/index.ts:1600:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/<my-username>/<some-path>/ts-boiler/src/index.ts' ]
}
Run Code Online (Sandbox Code Playgroud)
(出于隐私原因,我的用户名和文件夹结构被混淆)
相对导入(例如import { C } from './constants'
在文件内部)src/index.ts
工作正常。当将其更改为相应的设置import { C } from …
我已将现有Java应用程序导入到我的工作区中.我看到,在Application中的不同包中存在一个具有相同名称的类.
例如,名为"Status.java"的类与in一起出现
com.tata.model.common.Status;
com.bayer.frontlayer.dao.Status;
Run Code Online (Sandbox Code Playgroud)
当我尝试在一个类中使用它们时,例如如下所示
import com.tata.model.common.Status;
import com.bayer.frontlayer.dao.Status;
public class Adapter
{
}
Run Code Online (Sandbox Code Playgroud)
它开始在Eclipse声明中给出错误
该进口com.bayer.frontlayer.dao.Status与其他import语句碰撞
无论如何要解决这个问题而不改变类的名称?
谢谢.
我有以下源代码结构
/testapp/
/testapp/__init__.py
/testapp/testmsg.py
/testapp/sub/
/testapp/sub/__init__.py
/testapp/sub/testprinter.py
Run Code Online (Sandbox Code Playgroud)
其中testmsg
定义了以下常量:
MSG = "Test message"
Run Code Online (Sandbox Code Playgroud)
并且sub/testprinter.py
:
import testmsg
print("The message is: {0}".format(testmsg.MSG))
Run Code Online (Sandbox Code Playgroud)
但我得到了 ImportError: No module named testmsg
自包装结构以来它不应该工作吗?我真的不想在每个子模块中扩展sys.path,我甚至不想使用相对导入.
我在这做错了什么?
我有python 2.7.3
和ipython 1.2
启动和运行正常我的Linux
系统(ubuntu 12.04
),但要安装所需的课程matplotlab的更新版本.
在终端中运行此代码行后
user$ sudo easy_install -U distribute
user$ export PYTHONHOME=/usr/lib/python2.7/
Run Code Online (Sandbox Code Playgroud)
现在,每次我尝试运行python
或ipython
收到错误消息
ImportError: no module named site
Run Code Online (Sandbox Code Playgroud)
我该如何反转/解决这个问题?我迷路了.我看了其他类似的问题,但没有其他人使用Linux
,我不知道该怎么办.
我在Windows平台上安装了PyQt5并获得了importError:DLL加载失败.
我已经使用命令安装了pyqt5
pip3 install pyqt5
Successfully installed pyqt5-5.8.1
Run Code Online (Sandbox Code Playgroud)
我的Python版本如下:
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Run Code Online (Sandbox Code Playgroud)
导入错误如下:
from PyQt5.QtWidgets import QApplication
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
Run Code Online (Sandbox Code Playgroud)
感谢和问候
无法安装Scapy并且需要依赖性.我花了一些时间谷歌搜索解决方案,但所有'解决方案'似乎影响旧版本的Python,或根本不工作.
脚本:
#!/usr/bin/python
import threading
import Queue
import time
from scapy.all import *
class WorkerThread(threading.Thread) :
def __init__(self, queue, tid) :
threading.Thread.__init__(self)
self.queue = queue
self.tid = tid
print 'Worker: %d' %self.tid
def run(self) :
total_ports = 0
while True :
port = 0
try :
port = self.queue.get(timeout=1)
except Queue.Empty :
print 'Worker %d exiting. %d ports scanned' %(self.tid, total_ports)
return
#Scanning begins
ip = sys.argv[1]
response = sr1(IP(dst=ip)/TCP(dport=port, flags='S'), verbose=False, timeout=.2)
if response :
if response[TCP].flags == 18 …
Run Code Online (Sandbox Code Playgroud) 尝试读取 shapefile (.shp) 并在执行以下代码行后收到ImportError 。在执行下面的代码之前,我什至 pip 安装了 GDAL、geopandas、fiona 和 shapely。
shapefile = gpd.read_file(r'C:\Users\....\Data Analysis\shapefiles\louisville.shp')
Run Code Online (Sandbox Code Playgroud)
收到的错误如下,
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-164-16243badadbe> in <module>
----> 1 shapefile = gpd.read_file(r'C:\Users\....\Data Analysis\shapefiles\louisville.shp')
~\Anaconda3\lib\site-packages\geopandas\io\file.py in _read_file(filename, bbox, mask, rows, **kwargs)
164 by using the encoding keyword parameter, e.g. ``encoding='utf-8'``.
165 """
--> 166 _check_fiona("'read_file' function")
167 filename = _expand_user(filename)
168
~\Anaconda3\lib\site-packages\geopandas\io\file.py in _check_fiona(func)
78 def _check_fiona(func):
79 if fiona is None:
---> 80 raise ImportError(
81 f"the {func} requires the …
Run Code Online (Sandbox Code Playgroud) importerror ×10
python ×6
import ×2
java ×2
android ×1
dagger ×1
dllimport ×1
fiona ×1
installation ×1
ipython ×1
linux ×1
macos ×1
package ×1
pyqt5 ×1
python-3.x ×1
scapy ×1
tsconfig ×1
typescript ×1
ubuntu-12.04 ×1