Pycrypto python ошибка

After so many try with errors, now i have one solution for pycrypto and splunklib

Code of my Docker file that need to update :

FROM python:3.8-slim
RUN mkdir /app
WORKDIR /app
COPY requirements.txt /app
RUN pip install --no-cache-dir -r requirements.txt
RUN apt-get update && apt-get install -y --no-install-recommends gcc build- 
essential postgresql libpq-dev vim
COPY . /app
WORKDIR /app/api
EXPOSE 3000
CMD ["uvicorn", "api:app", "--host", "0.0.0.0",  "--port", "3000", "--reload"]

requirements.txt have

pycryptodome==3.14.1

splunk-sdk==1.6.19

splunklib==1.0.0

….

below error was showing for me when try to run above docker file code

            Building wheel for splunk-sdk (setup.py): started

            #9 80.50   Building wheel for splunk-sdk (setup.py): finished with status 'done'

            #9 80.51   Created wheel for splunk-sdk: filename=splunk_sdk-1.6.20-py3-none-any.whl 
            size=124053 sha256=ddce3663bb166c6732e18f1ed95187528c2a666b996eff7dfac00302cf9771d7

            #9 80.51   Stored in directory: /tmp/pip-ephem-wheel-cache-
            frl315nd/wheels/f7/a1/72/b2474c8ffe6b02fe24078e3413ed668fe6b85dfb17cd8e64c2

            #9 80.51   Building wheel for pycrypto (setup.py): started

            #9 92.72   Building wheel for pycrypto (setup.py): finished with status 'error'
            #9 92.76   error: subprocess-exited-with-error

            Running setup.py install for pycrypto: started

            #9 106.8   Running setup.py install for pycrypto: finished with status 'error'

            #9 106.9   error: subprocess-exited-with-error note: This error originates from a subprocess, and is likely not a problem with pip.

            #9 106.9 error: legacy-install-failure
            #9 106.9 Encountered error while trying to install package.
            #9 106.9 pycrypto

**Solution ** — Now i am updating docker file with below code

            FROM python:3.8-slim
            RUN mkdir /app
            WORKDIR /app
            COPY requirements.txt /app
            RUN apt-get update && apt-get install -y --no-install-recommends gcc build-essential postgresql libpq-dev vim
            RUN apt-get install -y --no-install-recommends libssl-dev libffi-dev
            RUN pip install --no-cache-dir -r requirements.txt
            COPY . /app
            WORKDIR /app/api
            EXPOSE 3000
            CMD ["uvicorn", "api:app", "--host", "0.0.0.0",  "--port", "3000", "--reload"]

enter image description here

ValueError: invalid version number '2.20.51.20100613'

I’m having problems installing pycrypto. Tried package manager: pip & easy_install, didn’t work. Tried to manually install it via «python setup.py install», the same error like the above appears.

I’ve followed the instructions here and got stuck at installing pycrypto after installing «mingW» gcc, g++ and msys-base (MSYS shell environment)

Not really sure what to do now after several days of trying.

Here’s the complete output of the error:

C:UsersDenzDesktop>pip install pycrypto
Downloading/unpacking pycrypto
  Running setup.py egg_info for package pycrypto
Installing collected packages: pycrypto
  Running setup.py install for pycrypto
    Traceback (most recent call last):
      File "", line 1, in ?
      File "C:UsersDenzDesktopbuildpycryptosetup.py", line 340, in ?
        core.setup(**kw)
      File "C:Python24libdistutilscore.py", line 149, in setup
        dist.run_commands()
      File "C:Python24libdistutilsdist.py", line 946, in run_commands
        self.run_command(cmd)
      File "C:Python24libdistutilsdist.py", line 966, in run_command
        cmd_obj.run()
      File "c:python24libsite-packagesdistribute-0.6.14-py2.4.eggsetuptools
commandinstall.py", line 53, in run
        return _install.run(self)
      File "C:Python24libdistutilscommandinstall.py", line 506, in run
        self.run_command('build')
      File "C:Python24libdistutilscmd.py", line 333, in run_command
        self.distribution.run_command(command)
      File "C:Python24libdistutilsdist.py", line 966, in run_command
        cmd_obj.run()
      File "C:Python24libdistutilscommandbuild.py", line 112, in run
        self.run_command(cmd_name)
      File "C:Python24libdistutilscmd.py", line 333, in run_command
        self.distribution.run_command(command)
      File "C:Python24libdistutilsdist.py", line 966, in run_command
        cmd_obj.run()
      File "C:Python24libdistutilscommandbuild_ext.py", line 253, in run
        force=self.force)
      File "C:Python24libdistutilsccompiler.py", line 1177, in new_compiler
        return klass (None, dry_run, force)
      File "C:Python24libdistutilscygwinccompiler.py", line 292, in init

    CygwinCCompiler.__init__ (self, verbose, dry_run, force)
  File "C:Python24libdistutilscygwinccompiler.py", line 83, in __init__
    self.gcc_version, self.ld_version, self.dllwrap_version = 
  File "C:Python24libdistutilscygwinccompiler.py", line 424, in get_versions
    ld_version = StrictVersion(result.group(1))
  File "C:Python24libdistutilsversion.py", line 40, in __init__
    self.parse(vstring)
  File "C:Python24libdistutilsversion.py", line 107, in parse
    raise ValueError, "invalid version number '%s'" % vstring
ValueError: invalid version number '2.20.51.20100613'

ATTENTION!!! As pycrypto is not maintained anymore, please switch to pycryptodome.

That’s how I did it. Extract from my README.md:

Installing on Windows

  1. Install Python
    Checked with Python 3.7 x64 on Windows 10 x64 Version 1803.

    • Get it from the Python homepage

    • Install launcher for all users

    • Add Python to PATH
      Adds %ProgramFiles%Python37 + Scripts to PATH

    • Use Customize Installation (!!! necessary for advanced options !!!)

    • Advanced Options

      • Install for all users
  2. Install Visual C++ Build Tools
    Checked with Visual Studio 2017.

    • Get the Build Tools from the Visual Studio download page (link as of 2018-11)

    • Install Visual C++ Build Tools with additional standard components

      • Windows 10 SDK
      • Visual C++ Tools for CMake
      • Core Tools for Testing
  3. Install necessary Python modules

    • Start an elevated(!!!) VS Developer Command Prompt (Run As Admin via Right Click)
    • Update PIP first: python -m pip install --upgrade pip
    • Install pycrypto module
      pycrypto has to compile some code due to legal restrictions on cryptography, so this is why the VC++ Build Tools had to be installed and the VS Developer Command Prompt had to be started.
      There’s a small issue with the pycrypto source, so as a workaround we have to include the correct header by setting the environment variable CL.
      set CL=-FI"%VCToolsInstallDir%includestdint.h"
      pip install pycrypto
    • Exit VS Developer Command Prompt: exit

The Visual C++ Build Tools may be deinstalled now, but it’s recommended to keep them installed to be able to upgrade pycrypto when necessary.

To install other modules just a normal but elevated(!!!) Command Prompt is needed (Run As Admin via Right Click).

first of all, you’re a wizard. So jot that down. I’ve been fighting this problem for three days. I know what it is now, when you click «install for all users» there’s an aditional dep that’s added along with it (you check one box, so python installs the other. I think it’s pre-compile some setup.py thing) anyways. You’re the real MVP. If you have problems with your wife/husband, boss, anyone, just let em know you’re legit a god. reference me if necessary. Thanks man. You’ve helped my project out in a huge way.

Попытался установить PyCrypto но не устанавливается с такой ошибкой:

Command "C:UsersAdminAppDataLocalProgramsPythonPython37-32python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\Admin\AppData\Local\Temp\pip-install-5l8x8czi\pycrypto\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:UsersAdminAppDataLocalTemppip-record-38549p5sinstall-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:UsersAdminAppDataLocalTemppip-install-5l8x8czipycrypto
You are using pip version 19.0.3, however version 19.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

p.s. это последняя часть

A common error you may encounter when using Python is modulenotfounderror: no module named ‘Crypto’.

This error occurs when the Python interpreter cannot detect the PyCrypto library in your current environment.

PyCrypto is no longer maintained and should not be used. You should use PyCryptodome, which is a maintained and upgraded fork of PyCrypto. Most applications that depend on PyCrypto will run unmodified

You can install PyCryptodome in Python 3 with python -m pip install pycryptodome.

This tutorial goes through the exact steps to troubleshoot this error for the Windows, Mac and Linux operating systems.


Table of contents

  • ModuleNotFoundError: no module named ‘Crypto’
    • What is ModuleNotFoundError?
    • What is PyCrypto?
  • Always Use a Virtual Environment to Install Packages
    • How to Install PyCryptodome on Windows Operating System
      • PyCryptodome installation on Windows Using pip
    • How to Install PyCryptodome on Mac Operating System using pip
    • How to Install PyCryptodome on Linux Operating Systems
      • Installing pip for Ubuntu, Debian, and Linux Mint
      • Installing pip for CentOS 8 (and newer), Fedora, and Red Hat
      • Installing pip for CentOS 6 and 7, and older versions of Red Hat
      • Installing pip for Arch Linux and Manjaro
      • Installing pip for OpenSUSE
      • PyCryptodome installation on Linux with Pip
  • Installing PyCryptodome Using Anaconda
    • Check PyCryptodome Version
  • Summary

ModuleNotFoundError: no module named ‘Crypto’

What is ModuleNotFoundError?

The ModuleNotFoundError occurs when the module you want to use is not present in your Python environment. There are several causes of the modulenotfounderror:

The module’s name is incorrect, in which case you have to check the name of the module you tried to import. Let’s try to import the re module with a double e to see what happens:

import ree
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
1 import ree
ModuleNotFoundError: No module named 'ree'

To solve this error, ensure the module name is correct. Let’s look at the revised code:

import re
print(re.__version__)
2.2.1

You may want to import a local module file, but the module is not in the same directory. Let’s look at an example package with a script and a local module to import. Let’s look at the following steps to perform from your terminal:

mkdir example_package
cd example_package
mkdir folder_1
cd folder_1
vi module.py

Note that we use Vim to create the module.py file in this example. You can use your preferred file editor, such as Emacs or Atom. In module.py, we will import the re module and define a simple function that prints the re version:

import re
def print_re_version():
    print(re.__version__)

Close the module.py, then complete the following commands from your terminal:

cd ../
vi script.py

Inside script.py, we will try to import the module we created.

import module
if __name__ == '__main__':
    mod.print_re_version()

Let’s run python script.py from the terminal to see what happens:

Traceback (most recent call last):
  File "script.py", line 1, in ≺module≻
    import module
ModuleNotFoundError: No module named 'module'

To solve this error, we need to point to the correct path to module.py, which is inside folder_1. Let’s look at the revised code:

import folder_1.module as mod
if __name__ == '__main__':
    mod.print_re_version()

When we run python script.py, we will get the following result:

2.2.1

Lastly, you can encounter the modulenotfounderror when you import a module that is not installed in your Python environment.

What is PyCrypto?

PyCrypto is a Python cryptography toolkit and contains a collection of modules for implementing various cryptographic algorithms and protocols including Cipher and Hash.

PyCrypto is no longer maintained and should not be used. You should use PyCryptodome, which is a maintained and upgraded fork of PyCrypto. Most applications that depend on PyCrypto will run unmodified

The simplest way to install PyCryptodome is to use the package manager for Python called pip. The following installation instructions are for the major Python version 3.

Always Use a Virtual Environment to Install Packages

It is always best to install new libraries within a virtual environment. You should not install anything into your global Python interpreter when you develop locally. You may introduce incompatibilities between packages, or you may break your system if you install an incompatible version of a library that your operating system needs. Using a virtual environment helps compartmentalize your projects and their dependencies. Each project will have its environment with everything the code needs to run. Most ImportErrors and ModuleNotFoundErrors occur due to installing a library for one interpreter and using the library with another interpreter. Using a virtual environment avoids this. In Python, you can use virtual environments and conda environments. We will go through how to install PyCryptodome with both.

How to Install PyCryptodome on Windows Operating System

First, you need to download and install Python on your PC. Ensure you select the install launcher for all users and Add Python to PATH checkboxes. The latter ensures the interpreter is in the execution path. Pip is automatically on Windows for Python versions 2.7.9+ and 3.4+.

You can check your Python version with the following command:

python3 --version

You can install pip on Windows by downloading the installation package, opening the command line and launching the installer. You can install pip via the CMD prompt by running the following command.

python get-pip.py

You may need to run the command prompt as administrator. Check whether the installation has been successful by typing.

pip --version

PyCryptodome installation on Windows Using pip

To install PyCryptodome, first, create the virtual environment. The environment can be any name, in this we choose “env”:

virtualenv env

You can activate the environment by typing the command:

envScriptsactivate

You will see “env” in parenthesis next to the command line prompt. You can install PyCryptodome within the environment by running the following command from the command prompt.

python3 -m pip install pycryptodome

We use python -m pip to execute pip using the Python interpreter we specify as Python. Doing this helps avoid ImportError when we try to use a package installed with one version of Python interpreter with a different version. You can use the command which python to determine which Python interpreter you are using.

If you are still getting a No module named Crypto error, check if you have previously installed PyCrypto using pip. You will need to uninstall it and your new install of PyCryptodome as follows:

python3 -m pip uninstall crypto
python3 -m pip uninstall pycryptodome
python3 -m pip install pycryptodome

How to Install PyCryptodome on Mac Operating System using pip

Open a terminal by pressing command (⌘) + Space Bar to open the Spotlight search. Type in terminal and press enter. To get pip, first ensure you have installed Python3:

python3 --version
Python 3.8.8

Download pip by running the following curl command:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

The curl command allows you to specify a direct download link. Using the -o option sets the name of the downloaded file.

Install pip by running:

python3 get-pip.py

To install PyCryptodome, first create the virtual environment:

python3 -m venv env

Then activate the environment using:

source env/bin/activate 

You will see “env” in parenthesis next to the command line prompt. You can install Django within the environment by running the following command from the command prompt.

python3 -m pip install pycryptodome

How to Install PyCryptodome on Linux Operating Systems

All major Linux distributions have Python installed by default. However, you will need to install pip. You can install pip from the terminal, but the installation instructions depend on the Linux distribution you are using. You will need root privileges to install pip. Open a terminal and use the commands relevant to your Linux distribution to install pip.

Installing pip for Ubuntu, Debian, and Linux Mint

sudo apt install python-pip3

Installing pip for CentOS 8 (and newer), Fedora, and Red Hat

sudo dnf install python-pip3

Installing pip for CentOS 6 and 7, and older versions of Red Hat

sudo yum install epel-release
sudo yum install python-pip3

Installing pip for Arch Linux and Manjaro

sudo pacman -S python-pip

Installing pip for OpenSUSE

sudo zypper python3-pip

PyCryptodome installation on Linux with Pip

To install PyCryptodome, first create the virtual environment:

python3 -m venv env

Then activate the environment using:

source env/bin/activate 

You will see “env” in parenthesis next to the command line prompt. You can install PyCryptodome within the environment by running the following command from the command prompt.

Once you have activated your virtual environment, you can install PyCryptodome using:

python3 -m pip install pycryptodome

Installing PyCryptodome Using Anaconda

Anaconda is a distribution of Python and R for scientific computing and data science. You can install Anaconda by going to the installation instructions. Once you have installed Anaconda, you can create a virtual environment and install PyCryptoDome.

To create a conda environment, you can use the following command:

conda create -n crypto python=3.8

You can specify a different Python 3 version if you like. Ideally, choose the latest version of Python. Next, you will activate the project container. You will see “crypto” in parentheses next to the command line prompt.

source activate crypto

Now you’re ready to install PyCryptodome using conda.

Once you have activated your conda environment, you can install PyCryptodome using the following command:

conda install -c conda-forge pycryptodome

Check PyCryptodome Version

Once you have successfully installed PyCryptodome, you can check its version. If you used pip to install PyCryptodome, you can use pip show from your terminal.

python3 -m pip show pycryptodome
Name: pycryptodome
Version: 3.14.1
Summary: Cryptographic library for Python

Second, within your python program, you can import the Crypto and then reference the __version__ attribute:

import Crypto
print(Crypto.__version__)
4.0.2

If you used conda to install PyCryptodome, you could check the version using the following command:

conda list -f pycryptodome
# Name                    Version                   Build  Channel
pycryptodome              3.14.1           py38hd9741ba_0    conda-forge

Summary

Congratulations on reading to the end of this tutorial. The modulenotfounderror occurs if you misspell the module name, incorrectly point to the module path or do not have the module installed in your Python environment. If you do not have the module installed in your Python environment, you can use pip to install the package. However, you must ensure you have pip installed on your system. You can also install Anaconda on your system and use the conda install command to install PyCryptoDome.

Go to the online courses page on Python to learn more about Python for data science and machine learning.

For further reading on missing modules in Python, go to the article:

  • How to Solve Python ModuleNotFoundError: no module named ‘urllib2’.
  • How to Solve ModuleNotFoundError: no module named ‘plotly’.

Have fun and happy researching!

Понравилась статья? Поделить с друзьями:
  • Pycharm ошибка traceback most recent call last
  • Pycharm ошибка please select a valid python interpreter
  • Pycharm ошибка 103
  • Pycharm no module named ошибка
  • Pxn 9613 ошибка драйвера