Я пытаюсь установить crypto
и pycrypto
в одной виртуальной среде.
[root@jnkslave01 tmp]# virtualenv test_pycrypto
New python executable in /root/tmp/test_pycrypto/bin/python
Installing setuptools, pip, wheel...done.
[root@jnkslave01 tmp]# source test_pycrypto/bin/activate
(test_pycrypto) [root@jnkslave01 tmp]# pip install crypto==1.4.1 pycrypto==2.6.1
Collecting crypto==1.4.1
/root/tmp/test_pycrypto/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
SNIMissingWarning
/root/tmp/test_pycrypto/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
/root/tmp/test_pycrypto/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
/root/tmp/test_pycrypto/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading https://pypi.storage.rackspace.com/packages/crypto-1.4.1-py2.py3-none-any.whl
Collecting pycrypto==2.6.1
/root/tmp/test_pycrypto/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
/root/tmp/test_pycrypto/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Requirement already satisfied: Naked in ./test_pycrypto/lib/python2.6/site-packages (from crypto==1.4.1)
Requirement already satisfied: shellescape in ./test_pycrypto/lib/python2.6/site-packages (from crypto==1.4.1)
Requirement already satisfied: requests in ./test_pycrypto/lib/python2.6/site-packages (from Naked->crypto==1.4.1)
Requirement already satisfied: pyyaml in ./test_pycrypto/lib/python2.6/site-packages (from Naked->crypto==1.4.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./test_pycrypto/lib/python2.6/site-packages (from requests->Naked->crypto==1.4.1)
Requirement already satisfied: certifi>=2017.4.17 in ./test_pycrypto/lib/python2.6/site-packages (from requests->Naked->crypto==1.4.1)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in ./test_pycrypto/lib/python2.6/site-packages (from requests->Naked->crypto==1.4.1)
Requirement already satisfied: idna<2.7,>=2.5 in ./test_pycrypto/lib/python2.6/site-packages (from requests->Naked->crypto==1.4.1)
Installing collected packages: crypto, pycrypto
Successfully installed crypto-1.4.1 pycrypto-2.6.1
(test_pycrypto) [root@jnkslave01 tmp]# python -c "from Crypto import Random"
(test_pycrypto) [root@jnkslave01 tmp]#
(test_pycrypto) [root@jnkslave01 tmp]# cat /etc/issue
CentOS release 6.9 (Final)
Kernel \r on an \m
Он отлично работает в CentOS 6.9
, но когда я пытаюсь сделать это на своем Mac. Выдает ошибку.
(test_pycrypto) ABCDEFG:~ myuser$ python -c "from Crypto import Random"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named Crypto
Когда я проверял, в чем разница между этими двумя настройками, я обнаружил, что в Mac
он устанавливает Crypto
в каталог crypto
в site-packages
.
На Mac
(test_pycrypto) ABCDEFG:~ myuser$ ls test_pycrypto/lib/python2.6/site-packages/crypto/
Cipher PublicKey Signature __init__.pyc decryptoapp.py pct_warnings.py settings.pyc
Hash Random Util app.py decryptoapp.pyc pct_warnings.pyc
Protocol SelfTest __init__.py app.pyc library settings.py
(test_pycrypto) ABCDEFG:~ myuser$ ls test_pycrypto/lib/python2.6/site-packages/Crypto/
Cipher PublicKey Signature __init__.pyc decryptoapp.py pct_warnings.py settings.pyc
Hash Random Util app.py decryptoapp.pyc pct_warnings.pyc
Protocol SelfTest __init__.py app.pyc library settings.py
На Mac он каким-то образом объединяет оба пакета и помещает одно и то же содержимое в оба каталога, тогда как на CentOS
оба каталога имеют разное содержимое.
На CentOS
(test_pycrypto) [root@jnkslave01 tmp]# ls test_pycrypto/lib/python2.6/site-packages/crypto
app.py app.pyc decryptoapp.py decryptoapp.pyc __init__.py __init__.pyc library settings.py settings.pyc
(test_pycrypto) [root@jnkslave01 tmp]# ls test_pycrypto/lib/python2.6/site-packages/Crypto/
Cipher Hash __init__.py __init__.pyc pct_warnings.py pct_warnings.pyc Protocol PublicKey Random SelfTest Signature Util
Я выполнил ту же команду для обеих настроек, также пробовал с Python 3
, у него такая же проблема.
Что я делаю неправильно на Mac, что вызывает эту проблему?
Файловая система Mac OS X нечувствительна к регистру, она не различает Crypto
и crypto
. Вы не можете установить оба в одной виртуальной среде. Разделите их.
Создайте или смонтируйте файловую систему с учетом регистра. Создайте новую HFS с учетом регистра с помощью команды newfs_hfs -s
(не экспериментируйте с действующей системой и всегда делайте резервную копию!) Или смонтируйте чувствительную к регистру файловую систему с внешнего диска или по сети.
Я не знаю, как именно Python ведет себя в файловой системе без учета регистра. Возможно, Python отличит crypto
от Crypto
и не может найти Crypto
, если crypto
был установлен.
Экспериментировать с файловыми системами довольно сложно, возможно, вы могли бы манипулировать одним из модулей - например, установить crypto
, переименовать его каталог и переписать код - исправить import crypto
и from crypto import…
. После этого установите Crypto
.
Еще один вопрос, если Mac не может различить, то, когда я делаю
from Crypto import Random
, он должен быть найден вtest_pycrypto/lib/python2.6/site-packages/crypto/
, потому что в этом каталоге есть пакетRandom
.