从requirements.txt安装依赖时遭遇版本冲突问题求助
解决Python依赖冲突:msal与pyOpenSSL的cryptography版本矛盾
我在创建项目虚拟环境并通过requirements.txt安装依赖时,遇到版本冲突。核心矛盾是msal 1.20.0要求cryptography<41,而pyOpenSSL 24.2.1要求cryptography>=41.0.5,两者版本范围无重叠,导致无法同时满足。
冲突详情
The conflict is caused by: The user requested cryptography==40.0.2 azure-storage-blob 12.14.1 depends on cryptography>=2.1.4 msal 1.20.0 depends on cryptography<41 and >=0.6 msoffcrypto-tool 5.0.0 depends on cryptography>=2.3 paramiko 2.12.0 depends on cryptography>=2.5 pyiotools 0.3.18 depends on cryptography pymiscutils 0.3.14 depends on cryptography pyopenssl 24.2.1 depends on cryptography<44 and >=41.0.5
我的requirements.txt内容
aenum==3.1.11 annotated-types==0.7.0 appdirs==1.4.4 APScheduler==3.9.1.post1 argcomplete==3.2.3 asn1crypto==1.5.1 atpublic==5.0 azure-core==1.26.1 azure-storage-blob==12.14.1 bcrypt==4.0.1 beautifulsoup4==4.11.1 bs4==0.0.1 build==1.1.1 CacheControl==0.14.0 case-conversion==2.1.0 certifi==2022.9.24 cffi==1.15.1 chardet==5.0.0 charset-normalizer==2.1.1 cleo==2.1.0 click==8.1.7 clipboard==0.0.4 cloudpickle==2.2.1 colorama==0.4.6 colour==0.1.5 crashtest==0.4.1 cryptography==40.0.2 cursor==1.3.5 cx-Oracle==8.3.0 decorator==4.4.2 dill==0.3.6 distlib==0.3.8 dulwich==0.21.7 exceptiongroup==1.2.2 fastjsonschema==2.19.1 filelock==3.13.1 fuzzywuzzy==0.18.0 gender-guesser==0.4.0 html-text==0.5.2 idna==3.4 imageio==2.22.4 imageio-ffmpeg==0.4.7 importlib_metadata==7.0.2 infi.systray==0.1.12 inflect==6.0.2 iniconfig==2.0.0 installer==0.7.0 isodate==0.6.1 jaraco.classes==3.3.1 keyring==24.3.1 lxml==4.9.1 maybe-else==0.2.1 mbstrdecoder==1.1.1 more-itertools==10.2.0 moviepy==1.0.3 msal==1.20.0 msgpack==1.0.8 msoffcrypto-tool==5.0.0 msrest==0.7.1 numpy==1.23.5 O365==2.0.22 oauthlib==3.2.2 office365==0.3.15 Office365-REST-Python-Client==2.3.16 olefile==0.46 packaging==24.0 pandas==1.5.1 paramiko==2.12.0 parsedatetime==2.6 pathmagic==0.3.14 pexpect==4.9.0 Pillow==9.3.0 pipx==1.4.3 pkginfo==1.10.0 platformdirs==4.2.0 pluggy==1.5.0 poetry==1.8.2 poetry-core==1.9.0 poetry-plugin-export==1.6.0 prettierfier==1.0.3 proglog==0.1.10 ptyprocess==0.7.0 pyarrow==17.0.0 pycparser==2.21 pydantic==2.8.2 pydantic_core==2.20.1 pydub==0.25.1 pyinstrument==4.4.0 pyiotools==0.3.18 PyJWT==2.6.0 pylance==0.16.0 pymiscutils==0.3.14 PyNaCl==1.5.0 pyOpenSSL==24.2.1 PyPDF2==2.11.2 pyperclip==1.8.2 pyproject_hooks==1.0.0 PyQt5==5.15.7 PyQt5-Qt5==5.15.2 PyQt5-sip==12.11.0 pysftp==0.2.9 pysubtypes==0.3.18 pytest==8.3.2 python-dateutil==2.8.2 python-docx==0.8.11 pytz==2022.6 pytz-deprecation-shim==0.1.0.post0 pywin32-ctypes==0.2.2 PyYAML==6.0.2 rapidfuzz==3.6.2 readchar==4.0.3 regex==2022.10.31 requests==2.28.1 requests-oauthlib==1.3.1 requests-toolbelt==1.0.0 Send2Trash==1.8.0 shellingham==1.5.4 simplejson==3.18.0 six==1.16.0 snowflake==0.11.0 snowflake-connector-python==3.12.0 snowflake-snowpark-python==1.20.0 snowflake._legacy==0.11.0 snowflake.core==0.11.0 sortedcontainers==2.4.0 soupsieve==2.3.2.post1 stringcase==1.2.0 tabulate==0.9.0 tomli==2.0.1 tomlkit==0.12.4 tqdm==4.64.1 trove-classifiers==2024.3.3 typepy==1.3.0 typing_extensions==4.12.2 tzdata==2022.6 tzlocal==4.2 urllib3==1.26.12 userpath==1.9.2 virtualenv==20.26.3 XlsxWriter==3.0.3 zipp==3.18.0
解决方法
方案1:降低pyOpenSSL版本
将pyOpenSSL降级到23.3.0,该版本依赖cryptography>=38.0.0,<42,与msal 1.20.0的cryptography<41完全兼容。修改requirements.txt对应行:
pyOpenSSL==23.3.0
方案2:升级msal版本
msal 1.24.0及以后版本的依赖要求更新为cryptography>=0.6,<42,可以兼容pyOpenSSL 24.2.1的cryptography>=41.0.5。修改requirements.txt对应行:
msal==1.24.0
方案3:移除固定的cryptography版本
如果没有强制要求使用cryptography==40.0.2,删掉requirements.txt中cryptography==40.0.2这一行,让pip自动计算满足所有依赖的最优版本。
内容的提问来源于stack exchange,提问作者rishi_stark
相关产品推荐
相关产品推荐

