Tag Archives: Python

Error in PIP3 execution of multi version Python by windows: module ‘enum’ has no attribute ‘intflag’?

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

summary :

This machine is equipped with python2.7 and python3.6. There is no problem when executing PIP and PIP2. When executing PIP3, you will be prompted:

C:\Users\>pip3
Traceback (most recent call last):
  File "e:\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "e:\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "E:\Python36\Scripts\pip3.exe\__main__.py", line 2, in <module>
  File "e:\python36\lib\re.py", line 142, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

reason:

English: This is likely caused by the package enum34. Since Python 3.4 there’s a standard library enum module, so you should install enum34, which is no longer compatible with the enum in the standard library since enum.intflag was added in Python 3.6

English: this may be caused by the enum34 package. Because there is a standard library enumeration module in Python 3.4, you should uninstall enum34, which is no longer compatible with enumerations in the standard library because enumerations. Intflag was added in Python 3.6

solutions:

pip uninstall enum34

#Uninstall enum34

After unloading, PIP3 was executed successfully. It took most of the day yesterday to solve the problem

C:\Users>pip3

Usage:
  pip3 <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

Pythonmodule ‘scipy.misc’ has no attribute ‘xxx’

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

Python error module ‘SciPy. Misc’ has no attribute ‘imresize’

Solution:

To install the pilot package, the command is as follows:

pip install Pillow

Then restart the python environment

Python error module ‘SciPy. Misc’ has no attribute ‘imread’

Solution:

Most of the solutions are to say that PIL third-party library is not installed. The library name is now pilow. It is recommended to use the command PIP install pilow to install directly. However, my problem has not been solved. I still report an error attributeerror: module ‘science. Misc’ has no attribute ‘imread’
after searching and trying, it is found that there is a problem with the version of SciPy, which can be perfectly solved by demoting to SciPy = = 1.2.1

pip install scipy==1.2.1

reasons:

If you look at many of the latest versions of scipy.misc.imresize, you will find the following at the top:

Imresize is not recommended

Imresize is obsolete in SciPy 1.0.0 and will be removed in 1.3.0

Use pillow instead: numpy. Array (image. Fromarray (ARR). Reset())

The 1.3.0 release was released yesterday, so if SciPy is downloaded on the system today, you may have obtained a new version, which will no longer be able to use the function

The document I quoted above proposes a code snippet (using numpy and PIL) that can be substituted

therefore, the root cause of the above similar problems is still the problem of the SciPy version

Attributeerror: module ‘sys’ has no attribute’ setdefaultencoding ‘solution?

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

module ‘sys’ has no attribute’ setdefaultencoding ‘solution

Reference article:

(1) Attributeerror: module ‘sys’ has no attribute’ setdefaultencoding ‘solution

(2) https://www.cnblogs.com/testyao/p/5658354.html

Let’s make a note.

After installing BS4 in Python, pychar still reports module not found error: no module named ‘BS4’

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

When learning web crawling, there is a problem in the first step

Executing sample code

from urllib.request import urlopen

from bs4 import BeautifulSoup

html = urlopen(” http://www.pythonscraping.com/exercises/exercise1.html “)

bsObj = BeautifulSoup(html, “html.parser”)

print(bsObj.h1)

Implementation results

Traceback (most recent call last):

File “D:/install/Python_ web Scraping/chapter1/BeautifulSoup.py”, line 2, in < module> from bs4 import BeautifulSoup ModuleNotFoundError: No module named ‘bs4’

Note: beautiful soup has been successfully installed in the terminal, but it still appears in idle

Solutions

1. In pychar Python file options, select the settings option and click in

2. Then select project interpreter

3. Double click pip

4. Search BS4, click Install, and the message of successful installation will be prompted

Python solves the problem of modulenotfounderror: no module named ‘queue’

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

We know that there are some incompatibilities between the two versions of python2 and python3. The introduction of queue in python3 will report this problem

In Python 3, it is introduced as follows:

1 import queue

In Python 2, we should introduce this method:

1 import Queue

For compatibility, it can be written as follows:

1 import sys
2 if sys.version > '3':
3     import queue as Queue
4 else:
5     import Queue

Python solves the problem of NameError: name ‘reload’ is not defined

Encountered this problem, for Python 2.X:

1 import sys
2 reload(sys)
3 sys.setdefaultencoding( " utf-8 " )

For Python 3.3 and below:
1 import imp
2 imp.reload(sys)

requires attention:
1. There is a big difference between Python 3 and Python 2. The Python 3 system uses utf- 8 encoding by default .
2. So, for the case of using Python 3, the code of sys.setdefaultencoding( ” utf-8 ” ) is not needed.
3. The most important thing is that there is no setdefaultencoding() function in Python 3 sys library.

For Python 3.4 and above:
1 import importlib
2 importlib.reload(sys)

Python,NameError: name ‘math’ is not defined

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

1 #-*- coding : utf-8 -*-
2 import math 3 4 def move(x, y, step, angle=0): 5 nx = x + step * math.cos(angle) 6 ny = y - step * math.sin(angle) 7 return nx, ny

Create a new Python file, save it as move, python interactive interface, import the move function, execute the function, and report an error

Before executing the function, enter

import math

Execute function without error

Error: need RCPT command

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

In a project, after executing a task, we can’t receive the set email. After exception capture, we find the following error in sending email:

smtplib.SMTPDataError: (503, b'Error: need RCPT command')

Abnormal recurrence

>>> cc_email = ['None']
>>> send_email(subject=subject, content=content, domain=domain, to_email=to_email, cc_email=cc_email)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/data/web/scripts/py/custom_send_email.py", line 43, in send_email
    msg.send()
  File "/usr/local/lib/python3.7/site-packages/django/core/mail/message.py", line 294, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 110, in send_messages
    sent = self._send(message)
  File "/usr/local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 126, in _send
    self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))
  File "/usr/local/lib/python3.7/smtplib.py", line 882, in sendmail
    (code, resp) = self.data(msg)
  File "/usr/local/lib/python3.7/smtplib.py", line 560, in data
    raise SMTPDataError(code, repl)
smtplib.SMTPDataError: (503, b'Error: need RCPT command')

After checking the code, it turned out that a list containing “None” was obtained when obtaining the CC mailbox

Solution:

Will CC_ Email = [‘none ‘] to CC_ Email = none or CC_ Email = []