简体   繁体   English

Python中的ImportError

[英]ImportError in Python

I tried to execute a program using geonames_rdf, but I cant execute it by this error: 我尝试使用geonames_rdf执行程序,但无法通过此错误执行它:

Traceback (most recent call last):
File "geo1.py", line 13, in <module>
 import geonames.config.log
ImportError: No module named config.log

I read several posts abot ImportError and I check the path of the system and it is correct. 我阅读了有关ImportError的几篇文章,并检查了系统路径,它是正确的。 I'm working in a VirtualBox with a fresh Ubuntu 16.04. 我正在使用新版Ubuntu 16.04在VirtualBox中工作。

The imports of my program are: 我的程序的导入是:

import sys
import os
import os.path
import logging
import geonames.config.log
import geonames.compat
import geonames.adapters.search

I've also tried add this line: 我也尝试添加此行:

sys.path.append('/usr/local/lib/python2.7/dist-packages/geonames/')

The command that I used to instal this package was 我用来安装此软件包的命令是

sudo pip install geonames_rdf

Try appending site-packages not dist-packages. 尝试附加站点软件包而不是dist软件包。 A bit of searching it looks like dist-packages is debian specific. 稍微搜索一下就好像dist-packages是debian特定的。

sys.path.append('/usr/local/lib/python2.7/site-packages/geonames/') sys.path.append('/ usr / local / lib / python2.7 / site-packages / geonames /')

Reason: 原因:

Since you're installing 3rd party python package via pip it will not go into dist-packages and python rightfully cannot find it on the path. 由于您是通过pip安装第3方python软件包,因此它将不会进入dist-packages,并且python正确地无法在路径中找到它。

Reference link: What's the difference between dist-packages and site-packages? 参考链接: dist-packages和site-packages有什么区别?

I just tried to use geonames_rdf, but I didn't know I needed it to do a geonames search so I installed geonames first, then discovered I had to install fiona and gdal (I'm on Windows, had to install these two using prebuilt whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/ ). 我只是尝试使用geonames_rdf,但我不知道我需要它来进行地理名称搜索,所以我先安装了地理名称,然后发现我必须安装fiona和gdal(我在Windows上,必须使用预构建的方式安装这两个来自http://www.lfd.uci.edu/~gohlke/pythonlibs/ )。 Don't know why these dependencies aren't baked into geonames. 不知道为什么这些依赖项没有纳入地名。

Anyway once I then installed geonames_rdf it seemed to install into the geonames folder in c:\\Python27\\lib\\site-packages, added at least the adapters package. 无论如何,一旦我安装了geonames_rdf,它似乎就安装在c:\\ Python27 \\ lib \\ site-packages中的geonames文件夹中,至少添加了适配器包。 In c:\\Python27\\lib\\site-packages\\geonames there is a config folder with log.py in it. 在c:\\ Python27 \\ lib \\ site-packages \\ geonames中,有一个包含log.py的配置文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM