ctypes初始化无法在python 2.7中使用本地应用程序引擎,django和virtualenv [英] ctypes init fails using local app engine, django and virtualenv with python 2.7

查看:68
本文介绍了ctypes初始化无法在python 2.7中使用本地应用程序引擎,django和virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临ctypes初始化的问题

I'm facing an issue with the init of ctypes

if int(_os.uname()[2].split('.')[0]) < 8:
ValueError: invalid literal for int() with base 10: '

我的应用由Python 2.7编写,基于Django,使用App Engine SDK和virtualenv在本地运行。它已经投入生产很长时间了,并且可以在其他计算机上本地成功运行。这意味着这是我的机器的本地问题。我使用的是Mac OSX 10.15.3 Catalina。

My app is written in Python 2.7 and based on Django, running locally using App Engine SDK and virtualenv. It's been in production for a long time and is running successfully locally on other machines. Meaning this is a local issue for my machine. I'm on Mac OSX 10.15.3 Catalina.

启动应用程序引擎本地开发服务器后,加载应用程序的任何页面时都会出现问题。 App Engine服务器已成功启动(我可以访问App Engine管理员webpag),但是正在引发上述异常(请参见下面的调用堆栈),因为它似乎是 os.uname()返回无效值。

The issues arises when I'm loading any page of my app, after starting the app engine local development server. The App Engine server is starting successfully (I can access the app engine admin webpag), but the above exception is being raised (see callstack below), as it seems os.uname() is returning an invalid value.

我自己运行 os.uname()时,结果似乎合法。

When running os.uname() myself, the result seems legit. Both when the virtualenv is activated or using the os/pyenv python interpeter.

Python 2.7.15 (default, Mar 15 2020, 22:00:51) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.uname()[2].split('.')[0]
'19'

我尝试过的解决方案:


  • 调用 os.uname()在virtualenv的内部和外部,它都能正常工作。

  • 使用系统Python 2.7.17安装创建虚拟环境

  • 使用pyenv创建虚拟环境带有3个不同的python 2版本(2.7.17、2.7.16、2.7.15)

  • Calling os.uname() inside and outside of the virtualenv, it works correctly.
  • Creating a virtualenv using the system Python 2.7.17 installation
  • Creating a virtualenvs using pyenv with 3 different python 2 versions (2.7.17, 2.7.16, 2.7.15)

看着整个调用堆栈,似乎从virtualenv外部的interpeter调用了ctypes init。在创建virtualenv时使用操作系统的python或pyenv python都是如此。也许在virtualenv中找不到ctypes?

Looking at the full callstack, it seems that ctypes init is being called from the interpeter outside of the virtualenv. This is true both if I'm using the OS's python or the pyenv python when creating the virtualenv. Maybe it's not finding ctypes in the virtualenv?

Traceback (most recent call last):
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 358, in __getattr__
    self._update_configs()
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 294, in _update_configs
    self._registry.initialize()
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 165, in initialize
    import_func(self._modname)
  File "/Users/myuser/.pyenv/versions/2.7.15/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/myuser/git/myproject/appengine_config.py", line 38, in <module>
    cloud_sql_conn_retry.monkey_patch_mysql_backend()
  File "/Users/myuser/git/myproject/server/utils/cloud_sql_conn_retry.py", line 14, in monkey_patch_mysql_backend
    from django.db.backends.mysql.base import DatabaseWrapper
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 38, in <module>
    from .creation import DatabaseCreation                      # isort:skip
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/backends/mysql/creation.py", line 4, in <module>
    from django.db.backends.base.creation import BaseDatabaseCreation
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 5, in <module>
    from django.core import serializers
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 23, in <module>
    from django.core.serializers.base import SerializerDoesNotExist
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/core/serializers/base.py", line 4, in <module>
    from django.db import models
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/models/__init__.py", line 3, in <module>
    from django.db.models.aggregates import *  # NOQA
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/models/aggregates.py", line 5, in <module>
    from django.db.models.expressions import Func, Star
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/models/expressions.py", line 6, in <module>
    from django.db.models import fields
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 14, in <module>
    from django import forms
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/forms/__init__.py", line 7, in <module>
    from django.forms.fields import *  # NOQA
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/forms/fields.py", line 17, in <module>
    from django.core import validators
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/core/validators.py", line 507, in <module>
    allowed_extensions=get_available_image_extensions(),
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/core/validators.py", line 498, in get_available_image_extensions
    from PIL import Image
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/PIL/Image.py", line 134, in <module>
    from pathlib2 import Path
  File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/pathlib2/__init__.py", line 5, in <module>
    import ctypes
  File "/Users/myuser/.pyenv/versions/2.7.15/lib/python2.7/ctypes/__init__.py", line 29, in <module>
    if int(_os.uname()[2].split('.')[0]) < 8:
ValueError: invalid literal for int() with base 10: ''

也,在python shell中导入ctypes时,一切正常。这是在虚拟环境中导入的库的路径。 ctypes和os是从pyenv interpeter导入的,而django是从virtualenv python导入的。我不清楚原因为何,我怀疑这可能与问题有关。

Also, when importing ctypes in python shell, it's all working. Here is the paths of libraries that are imported while inside the virtual env. ctypes and os are imported from the pyenv interpeter, and django is imported from the virtualenv python. It's not clear to me why, and I suspect this might be related to the issue.

>>> import ctypes
>>> print(ctypes)
<module 'ctypes' from '/Users/myuser/.pyenv/versions/2.7.15/lib/python2.7/ctypes/__init__.pyc'>
>>> import os
>>> print (os)
<module 'os' from '/Users/myuser/.pyenv/versions/2.7.15/lib/python2.7/os.pyc'>
>>> import django
>>> print (django)
<module 'django' from '/Users/myuser/git/myapp/env/lib/python2.7/site-packages/django/__init__.pyc'>

我在相同问题的google上找不到任何结果。
可能是什么问题?

I couldn't find any result on google with the same issue. What could be the issue?

推荐答案

问题是由配置了旧版本的PIL引起的 app.yaml 。开箱即用的App Engine支持最高为1.1.17版,不适用于最新的python 2版本。

The issue was caused by an old version of PIL that configured is configured in app.yaml. App Engine support out of the box up to version 1.1.17, which doesn't work with the latest python 2 version.

我安装了PIL的5.0.0版本和从App Engine设置中删除了1.1.17并解决了该问题。

I installed version 5.0.0 of PIL and removed 1.1.17 from the App Engine settings and it solved the problem.

这篇关于ctypes初始化无法在python 2.7中使用本地应用程序引擎,django和virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆