Tag Archives: python

ClobberError: The package ‘xxx‘ cannot be installed due to a path collision for ‘xx‘ This path alre

Original link: https://stackoverflow.com/questions/51217876/conda-update-anaconda-fails-clobbererror?newreg=2c51dd84b04b42c49294714471612f07

The reason for this problem is that the versions of related packages such as CONDA and pip are too low to be updated automatically. Solution: enter the following command on the command line:

conda clean --all
conda update --all

valueError: Length mismatch: Expected axis has 40 elements, new values have 38 elements

Background

I take the original model and prepare to run a new dataset. Of course, the columns will be different
the new dataset does not have a head, so I’m stupid to count a number of columns (it should be wrong. My original number of 38 is actually 40)
and report valueerror: length mismatch: expected axis has 40 elements, new values have 38 elements error

Solution ideas

My English is poor, so Google translated what this sentence means
valueerror: length mismatch: the expected axis has 40 elements and the new value has 38 elements

That is to say, I counted wrong
in order to prove it, I must output. The shape result is (100000, 40) OK, then I’ll recognize it and change it

Data processing and analysis

Before getting the dataset, you’d better take a shape to see how many rows and columns

train_df=pd.read_csv('data/train_small.txt',header=None,sep='\t')
print(train_df.shape)

Get (10000, 40)

For a dataset without a head, you need to define a header name

train_df.columns=['click']+['f'+str(i) for i in range(39)]
features=['f'+str(i) for i in range(39)]

It’s that simple

I write 39 because the target value in front of me has this

Error reason

It’s mainly because you can’t count.
it’s clearly said that there are 40 columns, so don’t be stubborn. Only 38 columns will be finished. Small mistakes are very simple

ModuleNotFoundError: No module named ‘notebook‘

ModuleNotFoundError: No module named ‘notebook’

Problem modulenotfounderror: no module named ‘notebook’

This problem occurred when running notebook today. Now I’d like to share with you how to solve this problem

terms of settlement

    open the terminal: Win + R, enter “CMD”, then “enter”
    activate the environment when you run the code: “CONDA activate + your environment name”
    after entering your environment, enter “Python – M PIP install Jupiter”, and then “enter”
    appears at the bottom to indicate that the installation is successful
    then enter: IPython notebook
    . This page indicates that the problem has been solved

Python environment error, bad interpreter: there is no file or directory

[xxxx@gs-server-7214 ~]$ /opt/anaconda3/bin/jupyter notebook
-bash: /opt/anaconda3/bin/jupyter: /opt/anaconda3/bin/python: Bad interpreter: No that file or directory
[xxxx@gs-server-7214 ~]$ /opt/anaconda3/bin/python3
Python 3.6.10 |Anaconda, Inc.| (default, May  8 2020, 02:54:21)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[1]+  Stop               /opt/anaconda3/bin/python3

    1. create a soft connection
    1. Jupiter has been installed through

/opt/anaconda3/bin/python3 - M PIP install Jupiter

    1. , and python can also be started under the full path, but the error is reported as above when starting Jupiter under the full path. The reason is that the default interpreter path of anaconda is/opt/anaconda3/bin/python, but there is no such file, Create a soft connection Python to point to the actual interpreter Python 3.6, as follows

- & gt</ Code> indicates soft connection </ OL>

[xxxx@gs-server-7214 bin]$ ll |grep python
-rwxrwxr-x 1 root root      237 10月 24 2019 ipython
-rwxrwxr-x 1 root root      237 10月 24 2019 ipython3
lrwxrwxrwx 1 root root        9 7月  16 16:31 python -> python3.6
lrwxrwxrwx 1 root root        9 8月  28 2020 python3 -> python3.6
-rwxrwxr-x 1 root root 11947112 5月   8 2020 python3.6
lrwxrwxrwx 1 root root       17 8月  28 2020 python3.6-config -> python3.6m-config
lrwxrwxrwx 1 root root        9 8月  28 2020 python3.6m -> python3.6
-rwxrwxr-x 1 root root     3477 8月  28 2020 python3.6m-config
lrwxrwxrwx 1 root root       17 8月  28 2020 python3-config -> python3.6m-config

2. Set the environment variable
and modify the . Bash in your user directory_ Profile file, add environment variable, export path =/opt/anaconda3/bin: $path , colon is separatorsource .bash_ Profile makes the environment variable effective, so you can start jupyter by directly entering jupyter notebook in your user directory.

[Solved] Selenium error: staleelementreferenceexception exception

StaleElementReferenceException

Problem reporting and solution

Problem reporting error

# clcik to the next page
web.find_element_by_xpath('//*[@id="nexthehe"]').click()

the element is no longer attached to the DOM : the element is no longer attached to the dom

Solution:

The element is no longer attached to the dom

Analyze the cause

It is possible that elements that are no longer attached to the DOM tree are guided (for example, document. Documentelement)

But the page content is not loaded and cannot be found

resolvent:

Still, looking for the element again

try:
    # clcik to the next page
    web.find_element_by_xpath('//*[@id="nexthehe"]').click()
    # time.sleep(1)
except Exception:
    print('failed to next page')
    web.find_element_by_xpath('//*[@id="nexthehe"]').click()

Python Redis: How to batch fuzzy Delete Keys

The method is as follows:

    # redis connection, chain refers to the test environment Redis environment
    r = redis.Redis(host='localhost', port=7622, db=0, decode_responses=True)

    item_list = r.keys(pattern='*app_access##qa_press_test*')
    
    # need to determine if there is a matching value, if not, it will report an error, so need to determine the processing
    if len(item_list):
        # Batch delete all cached application keys
        r.delete(*r.keys(pattern='app_access*'))
        logger.info("clear success...")
    else:
        logger.warn("with no data need to delete...")

PS: there is a detail to note here, that is, deleting directly without matching data will report an error, which needs to be handled

Note: conn.keys (‘test ‘) returns a list matching the corresponding pattern. Through the * sign, you can see that the parameters in the delete () method use variable parameters, that is, you can pass in a variable number of key values and delete them all.

[Solved] RuntimeError: No application found. Either work inside a view function or push an application contex

Python + Flash + Flash Sqlalchemy to realize MySQL database operation

Write test cases in Python to realize MySQL query

The test cases are as follows:

class MySQLTest(unittest.TestCase):

  def test_queryAll(self):
      uas = db.session.query(UserAgent).all()
      self.assertIsNotNone(uas)

      for ua in uas:
        print("\n")
        print(ua)


if __name__ == '__main__':
  unittest.main()

1、 Problem description

Error message below

RuntimeError: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/.

If no application is found, either work in the view function or push the application context

The first reaction should be related to writing test cases in Java Web applications, and the application context cannot be found


2、 Problem analysis

The test case starts a thread to execute database operation separately, which is independent of the flash application. It is unable to obtain the configuration information of the flash application context (including database connection information), so it is necessary to push the application context (inject context object)

This is why it works in the view function, which runs in the web container of flash.


3、 Solution

Python uses the with statement to manage context

The with statement is essentially context management
1. Context management protocol. Inclusion method__ enter__() And exit (), which support the protocol object to implement these two methods
2. The context manager defines the runtime context to be established when executing the with statement, and is responsible for executing the entry and exit operations in the context of the with statement block
3. Execute when entering the context__ enter__ Method. If the as var statement is set, the VaR variable accepts__ enter__() Method returns a value
4. If an exception occurs during runtime, exit the context manager. Call manager__ exit__ method.

Push the application context, that is, at the top where the thread starts executing code,
add with app.app_ context():

class MySQLTest(unittest.TestCase):

  def test_queryAll(self):
    with app.app_context():
      uas = db.session.query(UserAgent).all()
      self.assertIsNotNone(uas)

      for ua in uas:
        print("\n")
        print(ua)


if __name__ == '__main__':
  unittest.main()

4、 Result verification

Add with app.app_Context():
just write your own program logic, and the test case runs successfully

ModuleNotFoundError: No module named ‘sklearn.datasets.samples_generator‘

No module named ‘sklearn.datasets.samples_ generator’

Causes and solutions of error reporting

Problem reporting error

from sklearn.datasets.samples_generator import make_blobs

reason

samples_ The generator module has been removed in the new version of scikit learn .

samples_ The corresponding classes/functions in the generator module can be imported directly from sklearn. Datasets .

resolvent

Method 1:

Import make directly from sklearn. Datasets _ blobs

from sklearn.datasets import make_blobs

Method 2:

Version problem, reduce version

pip install scikit-learn==0.22.1

Reference: link

come on

thank you

work hard

Error in pyinstall package Python program: jinja2.exceptions.templatenotfound: Chart_ Solution to component.html

Recently, I wrote a visualization program in Python and used the daopycharts Library in the middle. There is no problem running it alone. However, after using pyinstall to package it into a separate EXE file, the running program reported an error: jinja2.exceptions.templatenotfound: chart_ component.html

After searching for relevant information on the Internet, it is said that pyinstaller and pyecarts are incompatible. The solutions after trying are as follows:

1. Change the packaging method and use the – D parameter to package it into a file instead of using the – f parameter to package it directly into an EXE file

as   pyinstaller -D -p d:\path run.py

-p   d: \ path is the site packages path of the imported package in your file. If the path of the pyecarts library on the computer is C: \ Python 37 \ lib \ site packages, it is written here as – P   C:\Python37\Lib\site-packages

Run.py is the target entry file that needs to be packaged

2. After pyinstaller is packaged, it will generate two folders: build and dist. open the dist folder and copy the pyecarts folder under C: \ Python 37 \ lib \ site packages to this directory

Run the packaged exe program, and the error message disappears

ModuleNotFoundError: No module named ‘ahocorasick‘ [100% Work Method]

ModuleNotFoundError: No module named ‘ahocorasick‘,
Install:

pip install pyahocorasick -i HTTPS://mirrors.aliyun.com/pypi/simple/

The following are the errors I encountered during installation:
error: Microsoft Visual C + + 14.0 is required. Get it with "Microsoft Visual C + + build tools,
Microsoft Visual C + + 14.0 needs to be installed

Recently, I was engaged in the knowledge mapping of natural language processing
but when building the system, I used a AC automaton word filtering , which is to remove sensitive words, such as

these sensitive words, which need to be replaced by some implied words or symbols such as * *. There are many ways to do this

- 1, AC automata
- 2, DFA filtering algorithm
- 3, replace filtering
- 4, regular expression filtering
for AC automata filtering, you need to use ahocorasick this library, now pyahocorasick

pip install pyahocorasick -i HTTPS://mirrors.aliyun.com/pypi/simple/

However, when installing pyahocorasick, it reported an error
that we need to install it

This is recommended to you error: Microsoft Visual C + + 14.0 is required. Get it with “Microsoft Visual C + + build tools, pro test 100% installation
it is offline installation, there will be no damage to the installation package;

The following is my successful installation of pyahocorasick:

Python 2.7: How to Install PIP

Python2 is no longer supported after PIP 2.1. Here you can use scripts to automatically download the highest supported version of PIP

1. Python2.7 the latest version of PIP installation file get-pip.py can be obtained by streaming

2. Install the file through Python 2.7

In the scripts folder, execute the following command to pull the get-pip.py file

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py

After downloading, execute the file to install the latest version of PIP supported by python2.7

python get-pip.py

You can see that the PIP version of automatic installation is 20.3

.4