Tag Archives: python

[Solved] ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

Solution

https://cryptography.io/en/latest/installation/

$ apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo
$ pip install --upgrade pip
$ export CRYPTOGRAPHY_DONT_BUILD_RUST=1
$ pip install cryptography

Solution process

      =============================DEBUG ASSISTANCE=============================
      If you are seeing a compilation error please try the following steps to
      successfully install cryptography:
      1) Upgrade to the latest pip and try again. This will fix errors for most
         users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
      2) Read https://cryptography.io/en/latest/installation.html for specific
         instructions for your platform.
      3) Check our frequently asked questions for more information:
         https://cryptography.io/en/latest/faq.html
      4) Ensure you have a recent Rust toolchain installed:
         https://cryptography.io/en/latest/installation.html#rust
      5) If you are experiencing issues with Rust for *this release only* you may
         set the environment variable `CRYPTOGRAPHY_DONT_BUILD_RUST=1`.
      =============================DEBUG ASSISTANCE=============================

  error: can't find Rust compiler

  If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.

  To update pip, run:

      pip install --upgrade pip

  and then retry package installation.

  If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.

  This package requires Rust >=1.41.0.
  ----------------------------------------
  ERROR: Failed building wheel for cryptography
Failed to build cryptography
ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

It is found that the solution is given above

      =============================DEBUG ASSISTANCE=============================
      If you are seeing a compilation error please try the following steps to
      successfully install cryptography:
      1) Upgrade to the latest pip and try again. This will fix errors for most
         users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
      2) Read https://cryptography.io/en/latest/installation.html for specific
         instructions for your platform.
      3) Check our frequently asked questions for more information:
         https://cryptography.io/en/latest/faq.html
      4) Ensure you have a recent Rust toolchain installed:
         https://cryptography.io/en/latest/installation.html#rust
      5) If you are experiencing issues with Rust for *this release only* you may
         set the environment variable `CRYPTOGRAPHY_DONT_BUILD_RUST=1`.
      =============================DEBUG ASSISTANCE=============================

============================= Debugging assistance =============================
If you see a compilation error, try the following steps
Install encryption successfully:
1) Upgrade to the latest pip and try again. This will fix most errors
users. See:https://pip.pypa.io/en/stable/installing/ upgrading-pip
2) Read specifically https://cryptography.io/en/latest/installation.html
for your platform instructions.
3) Check out our FAQ for more information:
https://cryptography.io/en/latest/faq.html
4) Make sure you have recently installed the Rust toolchain:
https://cryptography.io/en/latest/installation.html#rust
5)If you are experiencing problems with Rust in *this version*, you can
set the environment variable ' CRYPTOGRAPHY_DONT_BUILD_RUST=1 '.
============================= Debugging assistance =============================

First, upgrade pip

pip install --upgrade pip

After I upgrade, I will install again or report an error (some people on the Internet have solved it, if you have solved it, ignore the following contents)

Continue to look at the above content and say that my rust version is too low
to view the official website, you need to install the relevant dependencies

https://cryptography.io/en/latest/installation/

sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo

Re install or report an error, continue to follow the instructions to continue processing

     ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-km3x31je/matplotlib_fcb1836ff32b459797e98afb66f6211e/setup.py'"'"'; __file__='"'"'/tmp/pip-install-km3x31je/matplotlib_fcb1836ff32b459797e98afb66f6211e/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-7833r8p7
         cwd: /tmp/pip-install-km3x31je/matplotlib_fcb1836ff32b459797e98afb66f6211e/
    Complete output (44 lines):
    WARNING: The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host mirrors.aliyun.com'.
    ERROR: Could not find a version that satisfies the requirement numpy>=1.16 (from versions: none)
    ERROR: No matching distribution found for numpy>=1.16
    Traceback (most recent call last):
      File "/usr/local/lib/python3.7/site-packages/setuptools/installer.py", line 75, in fetch_build_egg
        subprocess.check_call(cmd)
      File "/usr/local/lib/python3.7/subprocess.py", line 363, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['/usr/local/bin/python', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmpd6d05k3_', '--quiet', 'numpy>=1.16']' returned non-zero exit status 1.

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-km3x31je/matplotlib_fcb1836ff32b459797e98afb66f6211e/setup.py", line 314, in <module>
        cmdclass=cmdclass,
      File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 152, in setup
        _install_setup_requires(attrs)
      File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 147, in _install_setup_requires
        dist.fetch_build_eggs(dist.setup_requires)
      File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 782, in fetch_build_eggs
        replace_conflicting=True,
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 768, in resolve
        replace_conflicting=replace_conflicting
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1051, in best_match
        return self.obtain(req, installer)
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1063, in obtain
        return installer(requirement)
      File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 838, in fetch_build_egg
        return fetch_build_egg(self, req)
      File "/usr/local/lib/python3.7/site-packages/setuptools/installer.py", line 77, in fetch_build_egg
        raise DistutilsError(str(e)) from e
    distutils.errors.DistutilsError: Command '['/usr/local/bin/python', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmpd6d05k3_', '--quiet', 'numpy>=1.16']' returned non-zero exit status 1.

    Edit setup.cfg to change the build options; suppress output with --quiet.

    BUILDING MATPLOTLIB
      matplotlib: yes [3.4.2]
          python: yes [3.7.10 (default, Jun 29 2021, 01:54:47)  [GCC 10.3.1
                      20210424]]
        platform: yes [linux]
           tests: no  [skipping due to configuration]
          macosx: no  [Mac OS-X only]

Setting environment variables

export CRYPTOGRAPHY_DONT_BUILD_RUST=1
pip install cryptography

It was a success this time.

[Solved] Ubuntu18.04 Install pyqt5 error: Command “python setup.py egg_info“ failed with error code 1 in /tmp/pip-build-92

Error in installing pyqt5 on Ubuntu 18.04:
command “Python setup.py egg”_ info” failed with error code 1 in /tmp/pip-build-92ggdywh/PyQt5/

As a result, the version of PIP is too low. The default system version is pip9, so we need to update the PIP version
the update method is as follows:

python3 -m pip install --upgrade pip

Because most of the time, we install python, or apt install Python directly, resulting in the installation of python2.7. If you just want to use a version of python, such as python3, you can uninstall python2. It’s better to uninstall to avoid conflicts.

How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)

Recently, when using pip to install the plug-in, the following warning message appears:

WARNING: Ignoring invalid distribution -ip (e:\python\python_ dowmload\lib\site-packages)

resolvent:

Find the directory where the error is reported in the warning message, and then delete the folder at the beginning of ~. That kind of thing is caused by the plug-in installation failure/Midway exit, which leads to the plug-in installation exception. Although the warning message does not affect, it has obsessive-compulsive disorder. Just delete the folder:

As for why the above problems appear?

Because a few days ago, when I was using Python 3.9 to build the robot framework environment, I needed to install wxPython, and then when the latest fashion was installed, later when the robot framework ride was installed,

One of the components it depends on does not support the latest version, and the component it depends on does not support Python 3.9, so there was an exception when installing the plug-in.

[Solved] Matplotlib ERROR: MatplotlibDeprecationWarning: Adding an axes using the same arguments…

Matplotlib error: MatplotlibDeprecationWarning: Adding an axes using the same arguments…
matpltlib error:

MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  self.axes = self.fig.add_subplot(111)  # Create a subgraph

The reason is to add subgraphs repeatedly, for example, self.axes = self.fig.add has been used_ Subplot (111) adds a subgraph, and then adds it repeatedly to report an error.

Solution:

Delete the subgraph of figure and add it again. Clear() is the method of figure class. Examples (the following are all examples in the class)

self.fig = plt.figure()
self.axes = self.fig.add_subplot(111)  # Create a subgraph
self.fig.clear() # Clear the subplot first
self.axes = self.fig.add_subplot(111) # Create a subplot

Solution warning: userwarning: fixedformatter should only be used together with fixedlocator (illustrated version)!)

Resolve warning

Error information problem code problem analysis and solution

Error information

• When we draw the edge histogram, the following warning will appear when we use the conventional method to convert the x-axis scale of the scatter plot to floating-point number!!!

UserWarning: FixedFormatter should only be used together with FixedLocator
  ax_main.set_xticklabels(xlabels)

Problem code

xlabels = ax_main.get_xticks().tolist() # Convert scale values to floating point numbers
ax_main.set_xticklabels(xlabels) # Set the scale value to floating point
plt.show()

• When you use the above code to convert the scale value to floating-point number, the same warning as the title will appear, but the x-axis scale of the scatter image displayed has been successfully converted to floating-point number, as shown in the figure below

Problem analysis

• Problem Description: This is a user warning: it is a warning caused by our nonstandard operation. It tells us that fixedformatter (scale form) can only be used with fixedlocator , but can’t use other methods to change the scale form!!!

solve the problem

• In the above we analyzed the causes of the warning, we should use the fixedlocator locator to change the fixedformatter (scale form), rather than directly convert the scale format, leading to the warning
• First, import the ticker module in Matplotlib library, and the code is as follows:

import matplotlib.ticker as mticker

label_format = '{:,.1f}'  # Create floating point format .1f one decimal
xlabels = ax_main.get_xticks().tolist()
ax_main.xaxis.set_major_locator(mticker.FixedLocator(xlabels)) # locate to the x-axis of the scatter plot
ax_main.set_xticklabels([label_format.format(x) for x in xlabels]) # Convert scales to floating point numbers using a list derivative loop
plt.show()

Image display:

• The complete code for drawing the above image is:

import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import pandas as pd

# Get the data
df = pd.read_csv(r'D:\9\mpg_ggplot2.csv')

# Create a canvas and split it into a grid
fig = plt.figure(figsize=(16, 10), dpi=80, facecolor='white')
grid = plt.GridSpec(4, 4, hspace=0.5, wspace=0.2)

# Add subgraphs
ax_main = fig.add_subplot(grid[:-1, :-1])
ax_right = fig.add_subplot(grid[:-1, -1], xticklabels=[], yticklabels=[])
ax_bottom = fig.add_subplot(grid[-1, :-1], xticklabels=[], yticklabels=[])

# Plot the bubble in the center

ax_main.scatter('displ', 'hwy'
                , s=df.cty * 4
                , data=df
                , c=df.manufacturer.astype('category').cat.codes
                , cmap='tab10'
                , edgecolors='gray'
                , linewidth=.5
                , alpha=.9)
# Plot the bottom histogram
ax_bottom.hist(df.displ, 40, histtype='stepfilled', orientation='vertical', color='deeppink')
ax_bottom.invert_yaxis() # make the y-axis inverse

# Plot the right histogram
ax_right.hist(df.hwy, 40, histtype='stepfilled', orientation='horizontal', color='deeppink')

# decorate the image
plt.rcParams['font.sans-serif'] = ['Simhei']
ax_main.set(title='Edge histogram \n engine displacement vs highway miles/gallon'
            , xlabel='Engine displacement (L)'
            , ylabel='Highway miles/gallon')
ax_main.title.set_fontsize = (20)

for item in ([ax_main.xaxis.label, ax_main.yaxis.label] + ax_main.get_xticklabels() + ax_main.get_yticklabels()):
    item.set_fontsize(14)

for item in [ax_bottom, ax_right]:
    item.set_xticks([])
    item.set_yticks([])

label_format = '{:,.1f}'  # Create floating point format .1f one decimal
xlabels = ax_main.get_xticks().tolist()
ax_main.xaxis.set_major_locator(mticker.FixedLocator(xlabels)) # locate to the x-axis of the scatter plot
ax_main.set_xticklabels([label_format.format(x) for x in xlabels]) # Convert scales to floating point numbers using a list derivative loop
plt.show()

[How to Solve] ImportError: No module named typing

python version 2.7
Error
This error occurs when using pip

Traceback (most recent call last):
File “C:\Python27\Scripts\pip-script.py”, line 9, in
load_entry_point(‘pip==21.1.3’, ‘console_scripts’, ‘pip’)()
File “C:\Python27\lib\site-packages\pkg_resources_init_.py”, line 542, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File “C:\Python27\lib\site-packages\pkg_resources_init_.py”, line 2569, in load_entry_point
return ep.load()
File “C:\Python27\lib\site-packages\pkg_resources_init_.py”, line 2229, in load
return self.resolve()
File “C:\Python27\lib\site-packages\pkg_resources_init_.py”, line 2235, in resolve
module = import(self.module_name, fromlist=[‘name’], level=0)
File “C:\Python27\lib\site-packages\pip_init_.py”, line 1, in
from typing import List, Optional
ImportError: No module named typing

The solution is to update python to 3, but I want to use 2.7, so this method does not work
Solution
I found that the version of pip is too high, and it is not compatible with python2, my version is pip21.1.3, so I need to set back the version of pip, the solution is as follows, just run it in order

curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
python get-pip.py
python -m pip install --upgrade "pip < 21.0"

Perfect solution, PIP version back, install again without error correction

[Solved] Python Using or importing the ABCs from ‘collections‘ instead of from ‘collections.abc‘ is deprecate

python Import Warning: Using or importing the ABCs from ‘collections’ instead of from ‘collections.abc’ is deprecated since Python 3.3, and in 3.10 it will stop working
Codes below:

from collections import Iterator

print(isinstance(iter([]), Iterator))  # True

# Console output:
# D:\Code_data\pycharm project\first test\08-iterable.py:2: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
#   from collections import Iterator
# True

Although the results have come out, there has always been an annoying warning (using or importing the ABCs from ‘collections’ instead of from’ collections. ABC ‘is predicted since Python 3.3, and in 3.10 it will stop working), The solution is to change
from collections import iterator
to
from collections.abc import iterator

module ‘win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9‘ has no attribute ‘CLSIDToClassMa

Using win32com encountered the following bug

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\win32com\client\gencache.py", line 534, in EnsureDispatch
    mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], bForDemand=bForDemand)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\win32com\client\gencache.py", line 391, in EnsureModule
    module = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\win32com\client\gencache.py", line 266, in GetModuleForTypelib
    AddModuleToCache(typelibCLSID, lcid, major, minor)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\win32com\client\gencache.py", line 552, in AddModuleToCache
    dict = mod.CLSIDToClassMap
AttributeError: module 'win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9' has no attribute 'CLSIDToClassMap'

The solution is:
delete the following folder, and the program can run normally

C:\Users\<my username>\AppData\Local\Temp\gen_py

This version of chromedriver only supports chrome version 92 crawler simulates the problem of Google plug-in version when the browser clicks and reports an error

When the crawler simulates the browser’s click, an error is reported in the version of the Google plug-in. In this case, the driver of the Google browser stored locally is incorrect and needs to be updated. The specific solutions are as follows:

resolvent:

Open the following website and download the corresponding version of chromedriver. If you can’t find the exact version number, just find 91

http://chromedriver.storage.googleapis.com/index.html

Be sure to download the driver according to your browser version

My version number is 91.0.4472.124, so I should download the driver corresponding to this version number. The website of download driver is the one above     http://chromedriver.storage.googleapis.com/index.html

After clicking in, the interface is as follows

Then find the corresponding version file, download it, unzip it, and copy and paste it into the

In the program error report, you need to delete or cover the previous version in the path where you installed Google before

Leave this new version of the driver. In addition to that, I need to make a copy to the IDE environment where you are running. I use the code written in Python language here, so I need to make a copy of the driver file to the local installation path of Python

At last, it ran successfully