Tag Archives: Python

Python uses poetry to install Sqlalchemy with an error attributeerror solution

This article mainly introduces the solution of “attributeerror ’emptyconstraint’ object has no attribute ‘allowed’ when executing PIP install Sqlalchemy in Python, but the error is reported when executing poetry installation.

Original address: Python uses poetry to install Sqlalchemy error attributeerror solution

pip install poetry Export requirements.txt Error: ERROR: In –require-hashes mode, all requirements must have their versions pinned with ==. These do not: cffi>=1.1 from https://…..

background

Python 3.9

pip 21.2.3

poetry   1.1.8

Execute the command to export requirements.txt

 poetry export  -f requirements.txt --output requirements.txt

seerequirements.txt

Each library has a hash encryption field

Execute the PIP install command

pip3 install --no-cache-dir --upgrade  -r requirements.txt

It’s wrong

#8 28.40 Collecting websockets==10.0
#8 28.51   Downloading websockets-10.0-cp39-cp39-manylinux2010_x86_64.whl (107 kB)
#8 29.38 Collecting cffi>=1.1
#8 29.38 ERROR: In --require-hashes mode, all requirements must have their versions pinned with ==. These do not:
#8 29.38     cffi>=1.1 from https://files.pythonhosted.org/packages/be/2a/6d266eea47dbb2d872bbd1b8954a2d167668481ff34ebb70ffdd1113eeab/cffi-1.14.6-cp39-cp39-manylinux1_x86_64.whl#sha256=f3ebe6e73c319340830a9b2825d32eb6d8475c1dac020b4f0aa774ee3b898d1c (from bcrypt==3.2.0->-r /code/requirements.txt (line 19))
------
executor failed running [/bin/sh -c pip install --no-cache-dir --upgrade -r /code/requirements.txt]: exit code: 1

Troubleshooting ideas

Uninstall cffi library and reinstall it. No

Regenerate the requirements.txt file and then install it. No

No, Google searched and found the issue of similar problems. It seems that it is a known problem, and the official poetry hasn’t fixed it yet. It only provides a way to avoid it

https://github.com/actions/virtual-environments/issues/2245

Solution

This flag is passed in the poetry export command  — without-hashes

poetry export --without-hashes -f requirements.txt --output requirements.txt

I use this method. It can be used in practice. It is suitable for small partners who use poetry

The following scenes have not been tried

Scene 1

Stop using PIP — constraints flag to pass packages with fixed hashes

Scene 2

If you use PIP directly, fix it to versions before 20.3

python -m pip install --upgrade pip==20.2.4

Scene 3

If you are using another   Virtualenv depends on pip. Please ensure that its version is fixed

python -m pip install --upgrade virtualenv==20.0.26

Or use the environment variable virtualenv_ PIP=20.2.4

Python Files Error: SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: tr

Syntaxerror was just reported when running the python file: ‘Unicode error)’ Unicode scape ‘codec can’t decode bytes in position 2-3: tr. in fact, the reason for this error is the escape problem.

sys.path.append('c:\Users\mshacxiang\VScode_project\web_ddt')

Cause analysis: in the windows system, the file path can be read by \, but in the Python string \, there is an escape meaning,

For example, \ t can represent tab and \ n represents line feed, so we need to take some measures to make \ not be interpreted as escape characters. There are currently 3 solutions

1. Add r before the path to keep the original value of the character.

sys.path.append(r'c:\Users\mshacxiang\VScode_project\web_ddt')

2. Replace with double backslash

sys.path.append('c:\\Users\\mshacxiang\\VScode_project\\web_ddt')

3. Replace with forward slash

sys.path.append('c:/Users/mshacxiang/VScode_project/web_ddt')

Python automatic error [How to Solve]

Use Python today. However, I met a mistake. A crazy stroke. Some say the path is wrong, others say it is… The information found on the Internet is also very few. Later, I suddenly found that the elements I can see temporarily on the page can be located and operated. What cannot be seen cannot be carried out… PS I didn’t join the full screen at this time

Seeing this, I suddenly thought whether it was caused by the nonfull screen of the page. OK. He really caused it. With the full-screen code, there will be no problem

driver.maximize_window()

 

Error in installing Python package — readtimeouterror

1、 Problem: error readtimeouterror is reported when installing Python package — read time out

2. Solutions
there are three methods: one is to switch the download source; Second, download the installation package of the corresponding platform and install it; Third, download the source code, compile and install
  The first method is to switch the download source recommendation

      https://pypi.tuna.tsinghua.edu.cn/simple

      http://pypi.douban.com/simple/

      Example: PIP install   Package name   — user -i   https://pypi.tuna.tsinghua.edu.cn/simple

      Permanent switch: under Linux, modify or create ~ /. PIP/pip.conf. The modification contents are as follows:

   [ global]

    index-url = https://pypi.tuna.tsinghua.edu.cn/simple

  Under windows, directly create a PIP directory in the user directory, such as C: \ users \ XX \ pip, and create a new file pip.ini, as follows:

  [ global]

    index-url = https://pypi.tuna.tsinghua.edu.cn/simple

 

  The second method is to download the installation package of the corresponding platform

      Baidu finds the PY package, selects the package of the corresponding platform, downloads and installs it, as shown in the figure below

 

 

 

 

The third method is to download the source code, compile and install

      If the installation package of the corresponding platform cannot be found, you can only download and compile the source code and then install it. For example, the last zip file in the figure below is the source code

 

 

 

 

python TypeError: an integer is required

Problem Description:

When using socket locally to transfer data to NetAssist, it is found that Python error typeerror: an integer is required error is reported after executing Python file

code:

  1 #!/usr/bin/env python3
  2 from socket import *
  3 udpSocket = socket(AF_INET, SOCK_DGRAM)
  4 destIp = input('enter ip:')
  5 destPort = input('enter port:')
  6 destData = input('enter data:')
  7 
  8 udpSocket.sendto(destData.encode('gb2312'),(destIp, destPort))

execution result:

enter ip:192.168.162.1
enter port:8080
enter data:haha
Traceback (most recent call last):
  File "udp-code.py", line 8, in <module>
    udpSocket.sendto(destData.encode('gb2312'),(destIp, destPort))
TypeError: an integer is required (got type str)

cause:

After querying the python document, it is found that the parameters passed do not meet the requirements of the socket. SendTo () method

Document Description:

s.sendto (string [, flag], address)
send UDP data. Send data to the socket. Address is a tuple in the form of (IPADDR, port) and specifies the remote address. The return value is the number of bytes sent
destport should be of type int

modify code:

  1 #!/usr/bin/env python3
  2 from socket import *
  3 udpSocket = socket(AF_INET, SOCK_DGRAM)
  4 destIp = input('enter ip:')
  5 destPort = int(input('enter port:'))
  6 destData = input('enter data:')
  7 
  8 udpSocket.sendto(destData.encode('gb2312'),(destIp, destPort))

result:

Summary:

After an error is reported, analyze the cause of the error according to the information

Query relevant documents and whether the parameter format meets the requirements