Tag Archives: pycharm

[Solved] SyntaxError: Generator expression must be parenthesized (widgets.py, line 152)

Run Django with pycharm, python manage Py runserver error

Checked the Internet and said to put widgets Delete the comma in line 152 of Py, which may be a compatibility problem between Python and Django. Try it. You can click the hyperlink above. Pycharm can quickly open the document, and then find the widgets under admin Py file is OK, because the prompt says form Django contrib. Admin import helpers, widgets, and options The PY file is in the admin directory.

[Solved] python Error: GuessedAtParserWarning: No parser was explicitly specified

f:\py\verification.py:148: GuessedAtParserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 148 of the file f:\py\verification.py. To get rid of this
warning, pass the additional argument 'features="lxml"' to the BeautifulSoup constructor.

It can operate normally, but an error message is prompted on the output console

soup = BeautifulSoup(response, ‘html’)

add: Features = "lxml" is fine

soup = BeautifulSoup(response, features="lxml")

Pychart remote debugging display picture, tkagg error report troubleshooting

It’s convenient to use pychart remote debugging program, but PLT can’t display pictures.

You can refer to pycham to remotely connect to the server and display the picture_ Cowboy does not catch a cold blog – CSDN blog

 

The following is the troubleshooting of errors reported by Matplotlib. Use (‘tkagg ‘) during the recent use of Matplotlib. Record it:  

Use the remote server debugger. In order to display the picture, modify matplotlib.use to report an error.

Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running

Xshell failed to open successfully. The error is eliminated after restarting xshell and xming.

But xming doesn’t pop up a window to display pictures. Restart debugging, here comes again

 

Then the above problem is probably not xshell and xming. Check env in the terminal and see display = localhost: 12.0

Recheck the pycharm running configuration. First clear the environment variable

Delete the display environment variable and display successfully.

After debugging and looking again, the error is reported again.

Check env again, display = localhost: 10.0

Add display = localhost: 10.0 again, the debugging is successful, try again, no problem, OK

[Solved] AttributeError: module ‘thread‘ has no attribute ‘start_new_thread‘

There is a package name thread in the project (the folder name in Python is also the package name), which conflicts with the thread library of the system. Just rename the folder in the project.

That is, change thread.py in the project to another name.

Right click thread.py → refactor → rename → in pycharm to change the name to be different from the system thread library.

[Solved] AttributeError: module ‘logging‘ has no attribute ‘Handler‘

Traceback (most recent call last):
  File "/home/odoo/python-dev/python_interview_exercise/python_libs/0-pandas.py", line 3, in <module>
    import numpy
  File "/home/odoo/.local/lib/python3.6/site-packages/numpy/__init__.py", line 223, in <module>
    from .testing import Tester
  File "/home/odoo/.local/lib/python3.6/site-packages/numpy/testing/__init__.py", line 8, in <module>
    from unittest import TestCase
  File "/usr/lib/python3.6/unittest/__init__.py", line 59, in <module>
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
  File "/usr/lib/python3.6/unittest/case.py", line 278, in <module>
    class _CapturingHandler(logging.Handler):
AttributeError: module 'logging' has no attribute 'Handler'

Solution:
the file name is logging.py and renamed to another name, such as demo_logging.py

How to Solve PIP3 error After upgrading pip3 install –upgrade pip

pip3 install –upgrade pip3 execution error after pip upgrade

Description
Traceback (most recent call last):
File “/home/brian/.local/bin/pip3”, line 7, in
from pip._internal.cli.main import main
File “/home/brian/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py”, line 60
sys.stderr.write(f”ERROR: {exc}”)
^
SyntaxError: invalid syntax

Solution
Execute python3 –version to determine the python3 version visit https://bootstrap.pypa.io/pip/ Find the get-pip.py file for the corresponding python version at this URL and execute wget in the terminal https://bootstrap.pypa.io/pip/3.8/get-pip.pypython3 get-pip.py

How to Solve Error: Error no module “Tkinter”

Error no module “Tkinter”

Principle:

Import Tkinter in python3 import Tkinter in python2

It’s just the difference in the case of the beginning in the python version.

Therefore, we can modify the startup version of Python. One is to directly modify the system version, and the other is to modify the specified version of Python file
here we mainly talk about how to modify the specified version of Python files.

Add the following two lines at the beginning of the .Py file:

#! /usr/bin/python2.7
# -*- coding utf-8 -*-

An error is reported when installing the package directly in pycharm, but it can be installed through the terminal. Error non zero exit code (2)

An error is reported when installing the package directly in pycharm, but it can be installed through the terminal

The problem description is shown in the figure below:

Error content: non zero exit code (2) direct installation will report the following error , but you can use the command to install in the terminal in pycharm, but it is too troublesome to install every time, which is not applicable to problem analysis

The PIP I use here is version 21.3.1. I checked my previous projects and found that pip21.2.4 can be installed normally without error, so I reduced the PIP version of this project to pip21.2.4. However, I don’t know the specific reason why pip21.3.1 can’t be used. The problem is solved

    enter the directory where the project environment is located
    open windows PowerShell in administrator mode and enter the directory where the environment is located. Use python.exe in the project to run the command - M PIP install PIP = = 21.2.4

    The goal here is to use the python execution command in the project instead of the global Python execution command . Enter pycharm to view the PIP version installation package . If there is no accident, it can be solved. I solved the problem in this way. At this time, if you like, you can upgrade PIP again. I try to upgrade pip to 21.3.1 again, which can be installed normally

    Reference blog

      https://blog.csdn.net/CNWorldisyourFC/article/details/110468251?utm_ medium=distribute.pc_ relevant.none-task-blog-title-2& spm=1001.2101.3001.4242. https://blog.csdn.net/weixin_ 51119842/article/details/110469060.