Tag Archives: python

Fileexistserror: [winerror 183] cannot create a file when it already exists. File rename code attached

FileExistsError: [WinError 183] Unable to create a file while it already exists. Attached file rename code

problem:

FileExistsError: [WinError 183] Unable to create the file while it already exists.

file rename we may encounter this problem

> So what should we do about it?

> Here is my file



>
>
>
>
>
>

Then the code runs successfully:



ah

Fatal Python error: initfsencoding: unable to load the file system codec

When both Python 2 and Python 3 exist and one of them fails to start, an error is reported in one of two cases
 
1. File error in python2 path failed to start python3

Fatal Python error: initfsencoding: Unable to load the file system codec
file “C:\Python27\Lib\encodings\__init__. Py “, line 123
ise CodecRegistryError,\
^>r> syntaxe> : invalid syntax
Current thread 0x000004dc (most recent call first):
2, file error in python3 path failed to start

File “E:\Python37\Lib\site.py”, line 177
File =sys.stderr)

s>xerror: invalid syntax
 
The above two cases in returning the same, the reason is to set the environment variable PYTHONPATH, PYTHONPATH is Python search path, we import the default module will search from the PYTHONPATH, environment variable is set to one version of the module path, lead to another version of the module loading path error when starting, leading to launch failure, this is according to the online tutorial to install Python when leaving a hole, the variable can not actually, The environment variable needs to be configured when the custom module is no longer in the Python installation path, so you can remove this environment variable, or just remove C:\Pythonxx\Lib

Perfect solution after deletion

Lookuperror: unknown encoding: cp65001 when executing Python

Appears during FETCH V8

E:\GitProject\svn_v8>fetch v8
Running: 'E:\GitProject\libcef\depot_tools\python276_bin\python.exe' 'E:\GitProj
ect\libcef\depot_tools\gclient.py' root
Traceback (most recent call last):
  File "E:\GitProject\libcef\depot_tools\\fetch.py", line 353, in <module>
    sys.exit(main())
  File "E:\GitProject\libcef\depot_tools\\fetch.py", line 348, in main
    return run(options, spec, root)
  File "E:\GitProject\libcef\depot_tools\\fetch.py", line 342, in run
    return checkout.init()
  File "E:\GitProject\libcef\depot_tools\\fetch.py", line 134, in init
    self.run_gclient('config', '--spec', self._format_spec())
  File "E:\GitProject\libcef\depot_tools\\fetch.py", line 76, in run_gclient
    return self.run(cmd_prefix + cmd, **kwargs)
  File "E:\GitProject\libcef\depot_tools\\fetch.py", line 63, in run
    print 'Running: %s' % (' '.join(pipes.quote(x) for x in cmd))
LookupError: unknown encoding: cp65001

LookupError: unknown encoding: cp65001
This error can be solved by changing the encoding mode:

chcp 1252

You can also set the default character encoding
HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe\CodePage by modifying the registry CodePage value

LookupError: Couldn’t find path to unrar library.

 

LookupError: Couldn’t find path to unrar library.
Mean to find unrar library paths, here we need to download the unrar library, in fact it is unrar. DLL this stuff, download url: http://www.rarlab.com/rar/UnRARDLL.exe or go to http://www.rarlab.com/rar_add.htm to find unrar. DLL download, should the need to compile under lunix.
The second step:
C:\Program Files (x86)\UnrarDLL = C:\Program Files (x86)\UnrarDLL = C:\Program Files (x86)\UnrarDLL = C:\Program Files (x86)\UnrarDLL = C:\Program Files (x86)\UnrarDLL = C:\Program Files (x86)\UnrarDLL = C:\Program Files (x86)\UnrarDLL = C:\Program Files (x86)\UnrarDLL = C:\Program Files (x86)\UnrarDLL = unrar.lib

Reproduced in: https://www.cnblogs.com/sea-stream/p/10329794.html

Lookuperror: couldn’t find path to unrear library! two thousand and twenty

Appear this kind of circumstance, because unrar there is dependent on a file unrar. DLL download address

when the download is complete must be installed in the default folder
then will pop up after the completion of the installation folder,
C:\Program Files (x86)\ Unrardll \x64
br> a>

>

<>bb4

C:\Program Files (x86)\ Unrardll \x64
C:\Program Files (x86)\ Unrardll \x64

Panda was unable to open the. Xlsx file, xlrd.biffh.XLRDError : Excel xlsx file; not supported

The reason is that XLRD was recently updated to version 2.0.1 and only supports.xls files. So Pandas. Read_Excel (‘ xxx.xlsx ‘) will return an error.
You can install an older version of XLRD and run it in CMD:
PIP uninstall XLRD
PIP install XLRD ==1.2.0
You can also open the.xlsx file with OpenPyXL instead of XLRD:
Df = pandas read_excel (‘ data. XLSX, engine = ‘openpyxl)

Python error: local variable ‘XXXX’ referenced before assignment

Recently, this error was encountered in coding: local variable ‘XXX’ Referenced before assignment, which solved this problem by looking up materials. This blog is very clear, so I collect it for you to view later.


Referenced Before Assignment Local Variable ‘XXX’ Referenced Before Assignment Local Variable ‘XXX’ Referenced Before Assignment Local Variable ‘XXX’ Referenced Before Assignment

[python] view plain copy
xxx = 23  
def PrintFileName(strFileName):   
    if xxx == 23:  
        print strFileName  
        xxx = 24  

PrintFileName("file")  

Error means that the variable ‘XXX’ is not defined before the reference. The global keyword in Python is used to refer to global variables, so I tried it, and it worked: * * * * * * * * * * * * * * * * * * * *

[python] view plain copy
xxx = 23  
def PrintFileName(strFileName):  
    global xxx  
    if xxx == 23:  
        print strFileName  
        xxx = 24  

PrintFileName("file")  

In Python, if you change the value of a variable with the same global name, it will become a local variable. The reference to that variable will be undefined before you change it. If you want to reference a global variable, and if you want to change it, you must include the global keyword.
The original link: http://blog.csdn.net/magictong/article/details/4464024


Added:
defines global variables in the class:

a = 1 
class File(object): 
    def printString(self,str): 
        global a  
        if a == 1:  
            print str  
            a = 24          
f = File()             
f.printString("file")  

json.load (file) error

1. Problem description
in running a very simple code:

 with open(json_file) as anno_file:
        anno = json.load(anno_file)

, an error:
json. The decoder. JSONDecodeError: Extra data: line 1 column 57054 char (57053)

 
Reason 2.
according to the prompt, the reason should be the json file of each line there is a limit to the number character (not more than 57053), but my line too much content
 

>
>
>
>
>
>
>

 with open(file_write, "w+") as f:
        for infor in dict_w[index]:
            dict_w1 = {infor: dict_w[index][infor]}
            json.dump(dict_w1, f)
            f.write("\n")

 
4. Further problems
run again at the beginning of reading and an error while reading code:
json. The decoder. JSONDecodeError: Extra data: line 2 column 1 (135) char

 

on. Load does not support decoding multiple JSON objects: Json. Loads , and json. The load ) does not decode multiple json object.

https://stackoverflow.com/questions/21058935/python-json-loads-shows-valueerror-extra-data
to fill: What are the JSON objects?

6. The solution of the problem further
way 1: put the object in a list to write again, and then load.

but in my practice, such a line of words too much, there will be 1 mentioned to
problem 2: read line by line, and add a list

Solving Python error: local variable ‘a’ referenced before assignment

First, the cause of the problem
Defines a variable outside a function, and then use the following variables inside a function in python, and change its value, the result error local variable ‘a’ referenced before the assignment, the code is as follows:

error reason: the python functions and global variables with the same, if you have to modify the value of the variable will become a local variable, the reference to the variable nature can appear not to define such a mistake.
Second, the solution
The problem is solved by declaring a as a global variable with the global keyword:

Error report and solution of import panda in Windows 10

If you use PIP Install Pandas in Windows 10, you will be unable to use Pandas and will receive an error, as shown in the figure below

You will need to change the version of Pandas at this time
Uninstall the previous Pandas first

pip uninstall pandas

Then specify the PIP to download version 1.0.1 of Pandas

pip install pandas==1.0.1