我在使用cx_freeze和scipy时编译exe时遇到了麻烦.特别是,我的脚本使用
from scipy.interpolate import griddata
Run Code Online (Sandbox Code Playgroud)
构建过程似乎成功完成,但是当我尝试运行已编译的exe时,我收到以下消息.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "gis_helper.py", line 13, in <module>
File "C:\Python27\lib\site-packages\scipy\__init__.py", line 103, in <module>
raise ImportError(msg)
ImportError: Error importing scipy: you cannot import scipy while
being in scipy source directory; please exit the scipy source
tree first, and relaunch your python intepreter.
Run Code Online (Sandbox Code Playgroud)
在查看scipy\_init__.py文件后,有以下内容:
if __SCIPY_SETUP__:
import sys as _sys
_sys.stderr.write('Running from scipy source directory.\n')
del _sys
else:
try:
from scipy.__config__ import show as …Run Code Online (Sandbox Code Playgroud) 编译exe后,pyinstaller build会抛出以下错误,这可能是由numpy\core\init.py引起的.
有一些建议,它与冲突的numpy安装有关,但是我已经卸载并重新安装了几次并且没有运气就搜索了任何其他安装.目前运行numpy-1.9 + MKL二进制文件.
我还将multiarray.pyd文件标记为spec文件中的二进制文件.没运气.
不知道是什么原因造成的,因为我对init文件结构并不是特别熟悉.知道如何进口这个吗?
回溯错误:
Traceback (most recent call last):
File "<string>", line 50, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\mpl_toolkits.basemap", line 15, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\matplotlib", line 133, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\matplotlib.rcsetup", line 19, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\matplotlib.colors", line 52, …Run Code Online (Sandbox Code Playgroud) 我在AWS Lambda中使用NLTK语料库(特别是停用词)时遇到了困难.我知道语料库需要下载并使用NLTK.download('stopwords')完成,并将它们包含在用于在nltk_data/corpora/stopwords中上传lambda模块的zip文件中.
代码中的用法如下:
from nltk.corpus import stopwords
stopwords = stopwords.words('english')
nltk.data.path.append("/nltk_data")
Run Code Online (Sandbox Code Playgroud)
这将从Lambda日志输出中返回以下错误
module initialization error:
**********************************************************************
Resource u'corpora/stopwords' not found. Please use the NLTK
Downloader to obtain the resource: >>> nltk.download()
Searched in:
- '/home/sbx_user1062/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- '/nltk_data'
**********************************************************************
Run Code Online (Sandbox Code Playgroud)
我还尝试通过包含直接加载数据
nltk.data.load("/nltk_data/corpora/stopwords/english")
Run Code Online (Sandbox Code Playgroud)
这会产生不同的错误
module initialization error: Could not determine format for file:///stopwords/english based on its file
extension; use the "format" argument to specify the format explicitly.
Run Code Online (Sandbox Code Playgroud)
它可能在从Lambda zip加载数据时遇到问题,需要将其存储在外部..比如S3,但这看起来有点奇怪.
知道什么格式的
有谁知道我哪里出错了?
我在AWS Lambda中遇到NLTK包的问题.但是我认为这个问题更多地与Lambda中的路径配置不正确有关.NLTK无法找到本地存储的数据库,而不是模块安装的一部分.SO上列出的许多解决方案都是简单的路径配置,可以在这里找到,但我认为这个问题与Lambda中的路径有关:
下载什么以使nltk.tokenize.word_tokenize有效?
还应该提到这也与我在此发布的上一个问题有关 使用NLTK语料库和Python中的AWS Lambda函数
但问题似乎更为笼统,因此我选择重新定义问题,因为它涉及如何正确配置Lambda中的路径环境以使用需要外部库(如NLTK)的模块.NLTK将很多数据存储在本地的nltk_data文件夹中,但是在lambda zip中包含此文件夹以供上传,它似乎找不到它.
Lambda func zip文件中还包含以下文件和目录:
\nltk_data\taggers\averaged_perceptron_tagger\averaged_perceptron_tagger.pickle
\nltk_data\tokenizers\punkt\english.pickle
\nltk_data\tokenizers\punkt\PY3\english.pickle
Run Code Online (Sandbox Code Playgroud)
从以下站点看来,var/task /似乎是lambda函数执行的文件夹,并且我尝试包含此路径无效.https://alestic.com/2014/11/aws-lambda-environment/
从文档中看来,似乎有许多环境变量可以使用但是我不知道如何将它们包含在python脚本中(来自windows,而不是linux)http://docs.aws.amazon. COM /λ/最新/ DG /电流支持,versions.html
希望在此处提出这个问题,任何人都有配置Lambda路径的经验.尽管有搜索,我还没有看到很多关于这个特定问题的问题,所以希望解决这个问题可能有用
代码就在这里
import nltk
import pymysql.cursors
import re
import rds_config
import logging
from boto_conn import botoConn
from warnings import filterwarnings
from nltk import word_tokenize
nltk.data.path.append("/nltk_data/tokenizers/punkt")
nltk.data.path.append("/nltk_data/taggers/averaged_perceptron_tagger")
logger = logging.getLogger()
logger.setLevel(logging.INFO)
rds_host = "nodexrd2.cw7jbiq3uokf.ap-southeast-2.rds.amazonaws.com"
name = rds_config.db_username
password = rds_config.db_password
db_name = rds_config.db_name
filterwarnings("ignore", category=pymysql.Warning)
def parse():
tknzr = word_tokenize
stopwords = ['i', 'me', 'my', 'myself', 'we', …Run Code Online (Sandbox Code Playgroud) python ×3
aws-lambda ×2
nltk ×2
pyinstaller ×2
build ×1
ctypes ×1
cx-freeze ×1
numpy ×1
pyz ×1
scipy ×1