操作系统:Windows7
Python:3.4(使用virtualenv)
好吧,我使用boto3构建了一个python文件,以便从AWS运行实例并且工作正常。
这是我的代码:
import boto3
from tabulate import tabulate
result = []
for instance in boto3.resource('ec2', region_name='sa-east-1').instances.filter(
Filters=[{'Name': 'instance-state-name', 'Values': ['running']}, {'Name': 'tag:Name', 'Values': ['<my_modules>*']},
{'Name': 'tag:Ambiente', 'Values': ['producao', 'Producao']}]):
result += [[instance.tags[next(idx for (idx, d) in enumerate(instance.tags) if d['Key'] == 'Name')]['Value'],
instance.private_ip_address,
instance.tags[next(idx for (idx, d) in enumerate(instance.tags) if d['Key'] == 'Ambiente')]['Value']]]
print(tabulate(sorted(result)))
现在,我想从中创建一个exe,为此,我正在使用Py2exe ...
我将&lt; .virtual_env&gt; \ Lib \ site-package \ botocore \ data中的* .json和&lt; .virtual_env&gt; \ Lib \ site-package \ botocore \ data \ s3的所有内容复制到\ data
这是我的setup.py文件:
from distutils.core import setup
from tabulate import tabulate
import os
import py2exe
dir_base = 'data'
aws_data_files = [(dir_base, [os.path.join(dir_base, 'endpoints.json'), os.path.join(dir_base, '_retry.json'),
os.path.join(dir_base, 'cacert.pem')])]
s3_module = 's3'
s3_dates = ['2006-03-01']
s3_files = ['paginators-1.json', 'service-2.json', 'waiters-2.json']
for dir_date in s3_dates:
list_files = []
for file in s3_files:
list_files.append(os.path.join(dir_base, s3_module, dir_date, file))
aws_data_files.append((os.path.join(dir_base, s3_module, dir_date), list_files))
print(tabulate(aws_data_files))
setup(
options={
'py2exe': {
'optimize': 0,
'packages': ['boto3', 'html']}},
console=['<my_python_file>.py'],
# package_data={'boto3', aws_data_files},
data_files=aws_data_files)
setup.py结果是:
python setup.py py2exe
------------------ ---------------------------------------------------------------------------------------------------------------------------
data ['data\\endpoints.json', 'data\\_retry.json', 'data\\cacert.pem']
data\s3\2006-03-01 ['data\\s3\\2006-03-01\\paginators-1.json', 'data\\s3\\2006-03-01\\service-2.json', 'data\\s3\\2006-03-01\\waiters-2.json']
------------------ ---------------------------------------------------------------------------------------------------------------------------
running py2exe
25 missing Modules
------------------
? Cookie imported from botocore.vendored.requests.compat
? OpenSSL imported from botocore.vendored.requests.packages.urllib3.contrib.pyopenssl
? Queue imported from botocore.vendored.requests.packages.urllib3.connectionpool
? _abcoll imported from botocore.vendored.requests.packages.urllib3.packages.ordered_dict
? backports imported from botocore.vendored.requests.packages.urllib3.packages.ssl_match_hostname
? certifi imported from botocore.vendored.requests.certs
? cookielib imported from botocore.vendored.requests.compat
? distutils.filelist imported from distutils.util
? distutils.text_file imported from distutils.extension, distutils.sysconfig
? distutils.versionpredicate imported from distutils.dist
? email.Utils imported from botocore.compat
? multiprocessing.SimpleQueue imported from concurrent.futures.process
? ndg imported from botocore.vendored.requests.packages.urllib3.contrib.pyopenssl
? ordereddict imported from botocore.compat
? pyasn1 imported from botocore.vendored.requests.packages.urllib3.contrib.pyopenssl
? readline imported from cmd, code, pdb
? simplejson imported from botocore.compat, botocore.vendored.requests.compat
? urllib.getproxies imported from botocore.vendored.requests.compat
? urllib.proxy_bypass imported from botocore.vendored.requests.compat
? urllib.quote imported from botocore.compat, botocore.vendored.requests.compat
? urllib.quote_plus imported from botocore.vendored.requests.compat
? urllib.unquote imported from botocore.compat, botocore.vendored.requests.compat
? urllib.unquote_plus imported from botocore.compat, botocore.vendored.requests.compat
? urllib.urlencode imported from botocore.compat, botocore.vendored.requests.compat, botocore.vendored.requests.packages.urllib3.request
? wcwidth imported from tabulate
Building 'dist\listar-maquinas-camada8.exe'.
Building shared code archive 'dist\library.zip'.
Copy c:\windows\system32\python34.dll to dist
Copy c:\python34x86\DLLs\unicodedata.pyd to dist\unicodedata.pyd
Copy c:\python34x86\DLLs\_ssl.pyd to dist\_ssl.pyd
Copy c:\python34x86\DLLs\_socket.pyd to dist\_socket.pyd
Copy c:\python34x86\DLLs\_decimal.pyd to dist\_decimal.pyd
Copy C:\Python\Envs\nimbos-business-core\lib\site-packages\win32\win32wnet.pyd to dist\win32wnet.pyd
Copy c:\python34x86\DLLs\_elementtree.pyd to dist\_elementtree.pyd
Copy c:\python34x86\DLLs\pyexpat.pyd to dist\pyexpat.pyd
Copy C:\Python\Envs\nimbos-business-core\lib\site-packages\win32\_win32sysloader.pyd to dist\_win32sysloader.pyd
Copy c:\python34x86\DLLs\select.pyd to dist\select.pyd
Copy c:\python34x86\DLLs\_bz2.pyd to dist\_bz2.pyd
Copy C:\Python\Envs\nimbos-business-core\lib\site-packages\win32\win32api.pyd to dist\win32api.pyd
Copy c:\python34x86\DLLs\_lzma.pyd to dist\_lzma.pyd
Copy c:\python34x86\DLLs\_hashlib.pyd to dist\_hashlib.pyd
Copy c:\python34x86\DLLs\_ctypes.pyd to dist\_ctypes.pyd
Copy c:\python34x86\DLLs\_multiprocessing.pyd to dist\_multiprocessing.pyd
Copy ExtensionDLL C:\Python\Envs\nimbos-business-core\lib\site-packages\pypiwin32_system32\pywintypes34.dll to dist\
但是当我尝试执行生成的exe文件时,我收到了这个:
Traceback (most recent call last):
File "C:\Python\Envs\nimbos-business-core\lib\site-packages\boto3\session.py", line 341, in resource
service_name, 'resources-1', api_version)
File "C:\Python\Envs\nimbos-business-core\lib\site-packages\botocore\loaders.py", line 132, in _wrapper
data = func(self, *args, **kwargs)
File "C:\Python\Envs\nimbos-business-core\lib\site-packages\botocore\loaders.py", line 378, in load_service_model
known_service_names=', '.join(sorted(known_services)))
botocore.exceptions.UnknownServiceError: Unknown service: 'ec2'. Valid service names are:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "listar-maquinas-camada8.py", line 5, in <module>
File "C:\Python\Envs\nimbos-business-core\lib\site-packages\boto3\__init__.py", line 92, in resource
return _get_default_session().resource(*args, **kwargs)
File "C:\Python\Envs\nimbos-business-core\lib\site-packages\boto3\session.py", line 347, in resource
has_low_level_client)
boto3.exceptions.ResourceNotExistsError: The 'ec2' resource does not exist.
The available resources are:
-