Tag Archives: python

[Solved] Python Networkx Error: Network error: random_state_index is incorrect

A few months ago, you can also use the Networkx package in Python. Recently, you rerun the previous code and report the following error

Network error: random_state_index is incorrect

Now the landlord has solved this problem. The specific steps are as follows:

First: open Anaconda prompt (Anaconda 3), demote Networkx package and decorator package, and enter the following code:

pip install --user decorator==4.3.0
pip install --user networkx==2.3

Second: turn off Anaconda prompt (Anaconda 3) and reopen Python to run without problem.

[Solved] Jupyter Notebook Start Error: Fatal error in launcher: Unable to create process using

Problem description

Previously, rename a CONDA virtual environment with the following command:

conda create -n torch --clone rl
conda remove -n rl --all

Then start jupyter from Torch virtual environment, and the following error is reported:

Fatal error in launcher: Unable to create process using
"g:\miniconda3\envs\rl\python.exe"
 "G:\miniconda3\envs\torch\Scripts\jupyter-notebook.EXE"

Reference solutions

I checked the online information and found that it was better after a mess… So I’m not sure which operation fixed the problem. What’s more certain is the last few executed commands:

pip uninstall ipython
pip uninstall jupyter
pip uninstall notebook

Or (after the above command is executed, try installing jupyter first. If the problem cannot be solved, execute the following command)

pip install pip-autoremove
pip-autoremove jupyter -y

Then install jupyter

pip install jupter

[Python] Right-click Selenium to Save the picture error: attributeerror: solution to module ‘pyscreen’ has no attribute ‘locationonwindow’

When crawling pictures with selenium module, simulate right clicking and select “save picture as” to save the picture (pyautogui module is not used)

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from time import sleep

url = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcdn.duitang.com%2Fuploads%2Fitem%2F201202%2F18%2F20120218194349_ZHW5V.thumb.700_0.jpg&refer=http%3A%2F%2Fcdn.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633348528&t=794e58b55dfe37e5f3082568feb89783'

driver = webdriver.Chrome()
driver.get(url)
element = driver.find_element_by_xpath('/html/body/img[1]')  

action = ActionChains(driver)  
action.move_to_element(element)  
action.context_click(element)  
action.send_keys(Keys.ARROW_DOWN)  
action.send_keys('v')  

action.perform()  
sleep(2)

driver.quit()  

When you execute the above code, you will find that you do not click the keyboard after right clicking, because the page is not controlled by selenium after right clicking. At this point, we need to use the pyautogui module, which is a module for automatically controlling the mouse and keyboard
you need to PIP download the wheel first

pip install pyautogui

Modified code:

from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from time import sleep
import pyautogui

url = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcdn.duitang.com%2Fuploads%2Fitem%2F201202%2F18%2F20120218194349_ZHW5V.thumb.700_0.jpg&refer=http%3A%2F%2Fcdn.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633348528&t=794e58b55dfe37e5f3082568feb89783'

driver = webdriver.Chrome()
driver.get(url)
element = driver.find_element_by_xpath('/html/body/img[1]') 

action = ActionChains(driver) 
action.move_to_element(element) 
action.context_click(element) 
action.perform() 

pyautogui.typewrite(['v']) 
sleep(1) 
pyautogui.typewrite(['1', '.', 'j', 'p', 'g'])
pyautogui.typewrite(['enter'])

sleep(1)

driver.quit() 

The red explosion will be found after execution:

attributeerror: module ‘pyscreen’ has no attribute ‘locateonwindow’

It is actually very simple to solve this problem
we directly download the highest version 0.9.53 after PIP install pyautogui
we only need to download version 0.9.50, so this problem will not exist

pip install pyautogui==0.9.50

Just execute the code again~

Please note that the module “sacrableu” has no “compute blue” attribute

Recently, I encountered the following errors when installing fairseq running experiment in machine translation related tasks:

AttributeError: module 'sacrebleu' has no attribute 'compute_bleu'

After consulting, it is a problem with sacrableu version 2.0. Only the following operations are required:

pip uninstall sacrebleu
pip install sacrebleu==1.5.1

Problem solved!

AttributeError: module ‘pkg_resources‘ has no attribute ‘declare_namespace‘

Record a problem. Anaconda3 CONDA version 4.6.7 is installed NB_ CONDA failed and damaged the original environment, resulting in an error as shown in the title.

It is speculated that there is a problem with the dependency. First, check the piptree and find that all dependencies are satisfied. However, I manually updated setuptools during the process of CONDA update CONDA. Although the update of CONDA update CONDA failed, the version of setuptools has been updated to 58.0.0,

– setuptools [required: >=36, installed: 58.0.0]

The highest requirement is only 36. It is suspected that the version is too new and the old version is not compatible. Then I tried the degraded version

pip uninstall setuptools

pip install setuptools==36.0.2

Problem solving.

Error when using OpenCV: use of unclared identifier ‘CV_ Bgr2rgb ‘solution

catalogue

1. Error message:

2. Analysis:

3. Solution:

1. Error message:

F:\test\Qt-Demo\mainwindow.cpp:55: error: use of undeclared identifier ‘CV_ BGR2RGB’

2. Analysis:

Because opencv is used   CV_ Bgr2gray did not declare it. Therefore, an undeclared identifier is prompted.

3. Solution:

Reference the following code in the header file:

#include < opencv2\imgproc\types_ c.h>

Error running docker container: starting container process caused “exec: \“python\“: executable file

Problem: minicanda3 virtual environment creates a python environment, and uses the following dockerfile to compile the docker image

FROM cuda10.2_pt1.5:09061
COPY . /workspace
WORKDIR /workspace
CMD ["python","run.py","/input_path","/output_path"]

Error using:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"python\": executable file not found in $PATH": unknown.

Try to add an environment variable. It takes effect in the container after adding, and python can be recognized. However, after the build image, python still has the same problem, and python cannot be recognized

EXPORT PATH="/root/miniconda3/bin:&PATH"

Try to establish a soft connection to python

ln -s /root/miniconda3/bin/python /usr/bin/python

It takes effect in the container after adding, and python can be recognized, but there is still an error after using the build image

docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/root/miniconda3/bin/path\": stat /root/miniconda3/bin/path: no such file or directory": unknown.

Analysis: an automatically executed command cannot locate the executable location

Solution: since Python for short cannot be located, just give the complete path directly./root/minikonda3/bin/python. Meanwhile, refer to some schemes and use run to add some necessary environments. The modified dockerfile is as follows:

FROM cuda10.2_pt1.5:09061
RUN apt-get update && apt-get install -y --no-install-recommends \
         build-essential \
         cmake \
         curl \
         ca-certificates \
         libjpeg-dev \
         libpng-dev && \
     rm -rf /var/lib/apt/lists/*
COPY . /workspace
WORKDIR /workspace
CMD ["/root/miniconda3/bin/python","run.py","/input_path","/output_path"]