使用PEX使用pandas打包python脚本

使用PEX使用pandas打包python脚本,第1张

概述我有一个简单的 python脚本依赖于熊猫.我需要用pex打包它,所以它没有依赖安装就执行了. import sysimport csv import argparseimport pandas as pd class myLogic(): def __init__(self): pass def loadData(self, data 我有一个简单的 python脚本依赖于熊猫.我需要用pex打包它,所以它没有依赖安装就执行了.

import sysimport csv import argparseimport pandas as pd class myLogic():    def __init__(self):        pass             def loadData(self,data_file):        return pd.read_csv(data_file,delimiter="|")    #command line interaction interface     def processinputArguments(self,args):        parser = argparse.ArgumentParser(description="my logic")        #transactions file name         parser.add_argument('-td','--data',type=str,dest='data',help='data file location'                            )               options = parser.parse_args(args)        return vars(options)    def main(self):        options = self.processinputArguments(sys.argv[1:])        data_file = options["data"]        data = self.loadData(data_file)        print data.head()if __name__ == '__main__':    ml = myLogic()    ml.main()

我正在尝试使用pex来做到这一点,所以我做了以下事情:

pex pandas -e myprogram.myLogic:main -o test1.pex

但是在运行生成的pex文件时出现此错误:

Traceback (most recent call last):  file ".bootstrap/_pex/pex.py",line 317,in execute  file ".bootstrap/_pex/pex.py",line 250,in _wrap_coverage  file ".bootstrap/_pex/pex.py",line 282,in _wrap_profiling  file ".bootstrap/_pex/pex.py",line 360,in _execute  file ".bootstrap/_pex/pex.py",line 418,in execute_entry  file ".bootstrap/_pex/pex.py",line 435,in execute_pkg_resources  file ".bootstrap/pkg_resources.py",line 2088,in loadimportError: No module named myLogic

我还尝试使用以下命令使用-c(switch for script)打包:

pex pandas -c myprogram.py -o test2.pex

但也得到一个错误:

Traceback (most recent call last):  file "/usr/local/bin/pex",line 11,in <module>    sys.exit(main())  file "/usr/local/lib/python2.7/dist-packages/pex/bin/pex.py",line 509,in main    pex_builder = build_pex(reqs,options,resolver_options_builder)  file "/usr/local/lib/python2.7/dist-packages/pex/bin/pex.py",line 486,in build_pex    pex_builder.set_script(options.script)  file "/usr/local/lib/python2.7/dist-packages/pex/pex_builder.py",line 214,in set_script    script,','.join(self._distributions)))TypeError: sequence item 0: expected string,distInfodistribution found
解决方法 到目前为止,唯一对我有用的选择是创建一个包含px的pex解释器,然后使用python脚本运送它.这可以按如下方式完成:

pex pandas -o my_interpreter.pex

但是当构建python版本是UCS4并且运行的版本是UCS2时,这会失败

总结

以上是内存溢出为你收集整理的使用PEX使用pandas打包python脚本全部内容,希望文章能够帮你解决使用PEX使用pandas打包python脚本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1196006.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存