最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

報(bào)錯(cuò)解決:Anaconda虛擬環(huán)境下使用uwsgi運(yùn)行uwsgi.ini報(bào)錯(cuò)ImportError問題

 更新時(shí)間:2026年02月10日 09:55:21   作者:長野飄蕩  
作者通過安裝和運(yùn)行uwsgi部署flask項(xiàng)目時(shí)遇到了各種問題,最后通過修改uwsgi配置文件、卸載并重新安裝uwsgi以及使用conda安裝uwsgi解決了問題

一個(gè)困擾了我好幾天的問題

首先,我安裝的是anaconda4.2.0,默認(rèn)是python3.5,但是出于需求,我使用anaconda創(chuàng)建了python3.7的虛擬環(huán)境,然后在該虛擬環(huán)境下使用uwsgi部署flask項(xiàng)目,寫好了配置uwsgi.ini文件后,敲下uwsgi --ini uwsgi.ini命令,得到的結(jié)果卻不是我想要的,報(bào)錯(cuò)如下:

Traceback (most recent call last):
  File "manage.py", line 2, in <module>
    from flask import Flask
  File "/Users/wangzhou/anaconda/envs/py37/lib/python3.7/site-packages/flask/__init__.py", line 14, in <module>
    from jinja2 import escape
  File "/Users/wangzhou/anaconda/envs/py37/lib/python3.7/site-packages/jinja2/__init__.py", line 33, in <module>
    from jinja2.environment import Environment, Template
  File "/Users/wangzhou/anaconda/envs/py37/lib/python3.7/site-packages/jinja2/environment.py", line 15, in <module>
    from jinja2 import nodes
  File "/Users/wangzhou/anaconda/envs/py37/lib/python3.7/site-packages/jinja2/nodes.py", line 19, in <module>
    from jinja2.utils import Markup
  File "/Users/wangzhou/anaconda/envs/py37/lib/python3.7/site-packages/jinja2/utils.py", line 16, in <module>
    from jinja2._compat import text_type, string_types, implements_iterator, \
  File "/Users/wangzhou/anaconda/envs/py37/lib/python3.7/site-packages/jinja2/_compat.py", line 31, in <module>
    import pickle
  File "/Users/wangzhou/anaconda/envs/py37/lib/python3.7/pickle.py", line 33, in <module>
    from struct import pack, unpack
  File "/Users/wangzhou/anaconda/envs/py37/lib/python3.7/struct.py", line 13, in <module>
    from _struct import *
ImportError: dlopen(/Users/wangzhou/anaconda/envs/py37/lib/python3.7/lib-dynload/_struct.cpython-37m-darwin.so, 2): Symbol not found: _PyByteArray_Type
  Referenced from: /Users/wangzhou/anaconda/envs/py37/lib/python3.7/lib-dynload/_struct.cpython-37m-darwin.so
  Expected in: flat namespace
 in /Users/wangzhou/anaconda/envs/py37/lib/python3.7/lib-dynload/_struct.cpython-37m-darwin.so
unable to load app 0 (mountpoint='') (callable not found or import error)

虛擬環(huán)境下直接運(yùn)行mamage.py是不會(huì)出現(xiàn)導(dǎo)包錯(cuò)誤ImportError的,我覺得十分匪夷所思,通過查詢資料,通常以下格式的錯(cuò)誤:

ImportError: dlopen(......
  Referenced from ......
  Expected in: flat namespace

嗯,基本上屬于版本不兼容相關(guān)的問題,然后我修改了uwsgi.ini配置文件里的home和pythonpath,改成我創(chuàng)建的那個(gè)虛擬環(huán)境py37的路徑,發(fā)現(xiàn)依舊還是無果,問題是不是在uwsgi這個(gè)點(diǎn)上?

我在python3.5,也就是默認(rèn)的anaconda的python下運(yùn)行uwsgi --ini uwsgi.ini是正常的,那個(gè)uwsgi是我通過pip install uwsgi安裝的,我查看了下版本:

wangzhou@Mac:~$ python -V
Python 3.5.2 :: Anaconda 4.2.0 (x86_64)
wangzhou@Mac:~$ uwsgi --python-version
3.5.2

然后我又查看了下虛擬環(huán)境

(py37) wangzhou@Mac:~$ python -V
Python 3.7.6
(py37) wangzhou@Mac:~$ uwsgi --python-version
3.7.3

恍然一拍大腿,原來如此啊!

然后我就使用pip uninstall uwsgi卸載了虛擬環(huán)境下的uwsgi,使用pip重新裝uwsgi,清除了pip的緩存,最后也裝成功了

(py37) wangzhou@Mac:~$ python -V
Python 3.7.6
(py37) wangzhou@Mac:~$ uwsgi --python-version
3.7.6

在我自以為就要搞定問題的時(shí)候,輸入uwsgi --ini uwsgi.ini命令后的結(jié)果依舊是上面那個(gè)導(dǎo)包錯(cuò)誤ImportError,誒,當(dāng)時(shí)心都涼了半截

后來又是找資料,終于發(fā)現(xiàn)了端倪,原來這一切的坑都是anaconda產(chǎn)生的,當(dāng)在虛擬環(huán)境中采用pip來安裝模塊后,anaconda會(huì)影響環(huán)境變量和PATH,總會(huì)出現(xiàn)奇怪的bug,比如上面的導(dǎo)包錯(cuò)誤ImportError,明明直接python manage.py正常的,采用uwsgi --ini uwsgi.ini來運(yùn)行卻會(huì)出岔子,讓人氣的不行

說了這么多,解決辦法很簡單

就是在虛擬環(huán)境中采用conda install uwsgi來安裝模塊,把用pip安裝的uwsgi卸載掉,然后運(yùn)行這個(gè)命令即可,不過通往成功的路往往是曲折的,報(bào)了個(gè)錯(cuò)如下:

PackagesNotFoundError: The following packages are not available from current channels:

下面直接貼命令:

anaconda search -t conda uwsgi

Using Anaconda API: https://api.anaconda.org
Run 'anaconda show <USER/PACKAGE>' to get more details:
Packages:
     Name                      |  Version | Package Types   | Platforms
     ------------------------- |   ------ | --------------- | ---------------
     IzODA/uwsgi               |   2.0.17 | conda           | zos-z
     ODSP-TEST/uwsgi           |   2.0.17 | conda           | zos-z
     auto/buildout.recipe.uwsgi |   0.0.22 | conda           | linux-64, linux-32
                                          : http://github.com/lcosmin/buildout.recipe.uwsgi
     auto/django-uwsgi-mail    |    1.1.1 | conda           | linux-64, linux-32
                                          : https://github.com/jaysonsantos/django-uwsgi-mail
     auto/eqb.recipe.uwsgi     |    0.0.2 | conda           | linux-64, linux-32
                                          : https://github.com/psychotechnik/eqb.recipe.uwsgi
     auto/infrae.uwsgi         |      1.0 | conda           | linux-64
                                          : https://svn.infrae.com/buildout/infrae.uwsgi/trunk/
     bgreen-litl/uwsgi         |    2.0.2 | conda           | osx-64
                                          : The uWSGI server
     conda-forge/uwsgi         |   2.0.18 | conda           | linux-64, osx-64

anaconda show conda-forge/uwsgi

Using Anaconda API: https://api.anaconda.org
Name:    uwsgi
Summary: The uWSGI project aims at developing a full stack for building hosting
services. Application servers (for various programming languages and
protocols), proxies, process managers and monitors are all implemented.

Access:  public
Package Types:  conda
Versions:
   + 2.0.12
   + 2.0.15
   + 2.0.16
   + 2.0.17
   + 2.0.17.1
   + 2.0.18

To install this package with conda run:
     conda install --channel https://conda.anaconda.org/conda-forge uwsgi

conda install --channel https://conda.anaconda.org/conda-forge uwsgi

Solving environment: done

==> WARNING: A newer version of conda exists. <==
  current version: 4.5.11
  latest version: 4.8.0
  
Please update conda by running
    $ conda update -n base conda

## Package Plan ##
  environment location: /Users/wangzhou/anaconda/envs/py37
  added / updated specs:
    - uwsgi

The following packages will be downloaded:
    package                    |            build
    ---------------------------|-----------------
    openssl-1.1.1d             |       h0b31af3_0         1.9 MB  conda-forge
    libxml2-2.9.10             |       h53d96d6_0         1.2 MB  conda-forge
    certifi-2019.11.28         |           py37_0         148 KB  conda-forge
    pcre-8.41                  |    h0a44026_1003         222 KB  conda-forge
    icu-64.2                   |       h6de7cb9_1        12.3 MB  conda-forge
    uwsgi-2.0.18               |   py37h08fe31f_3         1.9 MB  conda-forge
    ------------------------------------------------------------
                                           Total:        17.6 MB

The following NEW packages will be INSTALLED:
    icu:             64.2-h6de7cb9_1       conda-forge
    jansson:         2.11-h01d97ff_1001    conda-forge
    libiconv:        1.15-h01d97ff_1005    conda-forge
    libxml2:         2.9.10-h53d96d6_0     conda-forge
    pcre:            8.41-h0a44026_1003    conda-forge
    uwsgi:           2.0.18-py37h08fe31f_3 conda-forge
    yaml:            0.1.7-h1de35cc_1001   conda-forge

The following packages will be UPDATED:
    ca-certificates: 2019.11.27-0          defaults    --> 2019.11.28-hecc5488_0 conda-forge
    certifi:         2019.11.28-py37_0     defaults    --> 2019.11.28-py37_0     conda-forge

The following packages will be DOWNGRADED:
    openssl:         1.1.1d-h1de35cc_3     defaults    --> 1.1.1d-h0b31af3_0     conda-forge

Proceed ([y]/n)? y

Downloading and Extracting Packages
openssl-1.1.1d       | 1.9 MB    | ############################################################# | 100%
libxml2-2.9.10       | 1.2 MB    | ############################################################# | 100%
certifi-2019.11.28   | 148 KB    | ############################################################# | 100%
pcre-8.41            | 222 KB    | ############################################################# | 100%
icu-64.2             | 12.3 MB   | ############################################################# | 100%
uwsgi-2.0.18         | 1.9 MB    | ############################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

好了,切換到python3.7的虛擬環(huán)境輸入uwsgi --ini uwsgi.ini

*** Starting uWSGI 2.0.18 (64bit) on [Sat Jan 18 03:50:14 2020] ***
compiled with version: 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final) on 22 July 2019 16:53:49
os: Darwin-17.7.0 Darwin Kernel Version 17.7.0: Sun Jun  2 20:31:42 PDT 2019; root:xnu-4570.71.46~1/RELEASE_X86_64
nodename: Mac
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /Users/wangzhou/Desktop/Projects/candy_spider_api
writing pidfile to uwsgi.pid
detected binary path: /Users/wangzhou/anaconda/envs/py37/bin/uwsgi
chdir() to /Users/wangzhou/Desktop/Projects/candy_spider_api
your processes number limit is 1418
your memory page size is 4096 bytes
 *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
detected max file descriptor number: 4864
lock engine: OSX spinlocks
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :5000 # 使用nginx fd 3
Python version: 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 14:38:56)  [Clang 4.0.1 (tags/RELEASE_401/final)]
Python main interpreter initialized at 0x7f866f7021f0
python threads support enabled
your server socket listen backlog is limited to 10240 connections
your mercy for graceful operations on workers is 60 seconds
mapped 23090688 bytes (22549 KB) for 512 cores
*** Operational MODE: preforking+threaded ***
added /Users/wangzhou/anaconda/envs/py37/lib/python3.7/site-packages/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x7f866f7021f0 pid: 38043 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 38043)
spawned uWSGI worker 1 (pid: 38046, cores: 64)
spawned uWSGI worker 2 (pid: 38047, cores: 64)
spawned uWSGI worker 3 (pid: 38048, cores: 64)
spawned uWSGI worker 4 (pid: 38049, cores: 64)
spawned uWSGI worker 5 (pid: 38050, cores: 64)
spawned uWSGI worker 6 (pid: 38051, cores: 64)
spawned uWSGI worker 7 (pid: 38052, cores: 64)
spawned uWSGI worker 8 (pid: 38053, cores: 64)
*** Stats server enabled on 127.0.0.1:9191 fd: 25 ***

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 在Python中使用dict和set方法的教程

    在Python中使用dict和set方法的教程

    這篇文章主要介紹了在Python中使用dict和set方法的教程,dict字典是Python中的重要基礎(chǔ)知識(shí),set與其類似,需要的朋友可以參考下
    2015-04-04
  • Python之Sklearn使用入門教程

    Python之Sklearn使用入門教程

    這篇文章主要介紹了Python之Sklearn使用入門教程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • pandas DataFrame行或列的刪除方法的實(shí)現(xiàn)示例

    pandas DataFrame行或列的刪除方法的實(shí)現(xiàn)示例

    這篇文章主要介紹了pandas DataFrame行或列的刪除方法的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • Python Web服務(wù)器Tornado使用小結(jié)

    Python Web服務(wù)器Tornado使用小結(jié)

    最近在做一個(gè)網(wǎng)站的后端開發(fā)。因?yàn)槌跗谥挥形乙粋€(gè)人做,所以技術(shù)選擇上很自由。在 web 服務(wù)器上我選擇了 Tornado。雖然曾經(jīng)也讀過它的源碼,并做過一些小的 demo,但畢竟這是第一次在工作中使用,難免又發(fā)現(xiàn)了一些值得分享的東西
    2014-05-05
  • Python面向?qū)ο笾鄳B(tài)原理與用法案例分析

    Python面向?qū)ο笾鄳B(tài)原理與用法案例分析

    這篇文章主要介紹了Python面向?qū)ο笾鄳B(tài)原理與用法,結(jié)合具體案例形式分析了Python多態(tài)的具體功能、原理、使用方法與操作注意事項(xiàng),需要的朋友可以參考下
    2019-12-12
  • Python實(shí)現(xiàn)智能貪吃蛇游戲的示例代碼

    Python實(shí)現(xiàn)智能貪吃蛇游戲的示例代碼

    我想大家都玩過諾基亞上面的貪吃蛇吧,這篇文章將帶你一步步用python語言實(shí)現(xiàn)一個(gè)snake小游戲,文中的示例代碼講解詳細(xì),感興趣的可以了解一下
    2022-07-07
  • Python日期時(shí)間模塊arrow的具體使用

    Python日期時(shí)間模塊arrow的具體使用

    Python中有很多時(shí)間和日期處理的庫,有time、datetime等,本文主要介紹了一下arrow,arrow是一個(gè)專門處理時(shí)間和日期的輕量級Python庫,感興趣的可以了解一下
    2021-09-09
  • 淺談Python的方法解析順序(MRO)

    淺談Python的方法解析順序(MRO)

    這篇文章主要介紹了淺談Python的方法解析順序(MRO),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • Python中ablang包語法、參數(shù)和最佳實(shí)踐

    Python中ablang包語法、參數(shù)和最佳實(shí)踐

    ablang是基于深度學(xué)習(xí)的抗體序列分析工具包,提供嵌入表示、突變預(yù)測和結(jié)構(gòu)分析功能,應(yīng)用于計(jì)算免疫學(xué)、藥物開發(fā)等領(lǐng)域,通過pip安裝,需結(jié)合實(shí)驗(yàn)驗(yàn)證,確保序列質(zhì)量與參數(shù)正確,感興趣的朋友跟隨小編一起看看吧
    2025-08-08
  • 使用python實(shí)現(xiàn)ftp的文件讀寫方法

    使用python實(shí)現(xiàn)ftp的文件讀寫方法

    今天小編就為大家分享一篇使用python實(shí)現(xiàn)ftp的文件讀寫方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07

最新評論

广丰县| 顺义区| 唐海县| 四平市| 庆云县| 眉山市| 梨树县| 资源县| 遵义县| 内乡县| 兴仁县| 麻阳| 盐边县| 平遥县| 昂仁县| 廉江市| 北京市| 南充市| 洪泽县| 辉县市| 江川县| 德江县| 中山市| 望都县| 屯昌县| 左权县| 紫云| 桓仁| 九龙坡区| 景泰县| 延安市| 松桃| 汤阴县| 绥芬河市| 绍兴市| 无锡市| 茌平县| 临漳县| 洛川县| 龙岩市| 运城市|