Tag Archives: pycharm

PyCharm: How to Solve Tensorflow_datasets Import Error

[error scenario]

(1) Pycharm version: pycharm 2021.2.2 (Community Edition)

(2)Python Interpret:Anaconda3(64-bit)

(3)Python 3.8.11

(4)tensorflow 2.3

When using RNN for text classification experiment, the following import statement at the beginning of the program makes an error:

import tensorflow_datasets as tfds

[solution]

Select the menu file -> Open the settings dialog box, expand the project: [current project name] item in the left panel, select the python interpret item, and select the “+” icon in the right panel to open the available packages dialog box. The settings dialog box is shown in the following figure:

Enter tensorflow datasets in the search bar at the top of the available packages dialog box. After the tensorflow datasets module name appears in the list below the search bar, select it, and then click the install package button at the bottom to wait for the installation to complete. [note] the middle line of the package name here is a middle line, not an underscore, but an underscore in the front and back import statements.

Python Error: Process finished with exit code -1073740791 (0xC0000409)

Case 1 is also the case of more on-line): (graphics card) insufficient memory

At this time, we can adjust the memory in pycharm:
Press Shift + Ctrl + A to search for

where:
XMS in xms128m refers to the memory required for program startup, 128M is the size
xmx1011m in Xmx, Xmx refers to the memory required for program running, 1011m is the size
increase it. Of course, your hardware should be able to withstand this setting

How to Solve Pychart configuration import torch error

Pycharm configuration import torch report error Traceback
Error content error screenshot solution
Problem solved

Error content

Traceback (most recent call last):
File “”, line 1, in
File “D:\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py”, line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named ‘torch’
Screenshot of error report
Image:
Solution:
File–>Settings

Python Interpreter

Click the ‘+’
Search torch
Choose install Package

Importing the torch again in the Python Console shows True

Done!

[Python] error reported when reading DICOM file pydicom.errors.invaliddicomerror

[Python] error reported when reading DICOM file pydicom.errors.invaliddicomerror

When using Python to read and display DICOM files, the code is as follows:

import pydicom
import matplotlib.pyplot as plt
a = pydicom.read_file(r'C:\Users\shdn\Desktop\004.dcm')
print(a)
plt.imshow(img)
plt.show()

However, I sometimes encounter the following errors (I made the following error when reading the data given by the hospital):

The reason for this error is that the data given by the hospital may not be processed, and the file meta information header is missing, so it cannot be read directly. Solution: force reading.

The code is as follows:

import pydicom
import matplotlib.pyplot as plt
a = pydicom.read_file(r'C:\Users\shdn\Desktop\004.dcm' , force=True)
a.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian
print(a)
plt.imshow(img)
plt.show()

Successfully resolved:

[Solved] C error: expected 1 fields in line 3, saw 2 processing method

1. There is a CSV file that I read directly with the pandas library, and an error is reported: error tokenizing data. C error: expected 1 fields in line 3, saw 2. There should be a problem with the format. It can only be opened after it is opened and saved again. However, because there are many files, I wonder if I can read the CSV file by other methods;

2. Read through the CSV library, traverse, and merge:

import pandas as pd
import csv


path = 'the location of file'

test = pd.DataFrame()
data = csv.reader(open(path, 'r'))
for d in data:
    # print(d)
    result = pd.DataFrame(d).T
    test = pd.concat([test,result])
test = test.reset_index(drop = True)

3. Finally, you will get the dataframe of test, which is the same as the file read by pandas after saving

[Solved] Mujoco Error: Missing path to your environment variable.

Using mujoco to report an error: missing path to your environment variable

Question:

Recently, you want to use pycharm to run the server program in the local server environment. Follow https://www.jb51.net/article/195691.htm After step configuration, try running Import mujoco_Py , error reported:

Missing path to your environment variable.  
Current values LD_LIBRARY_PATH= 
Please add following line to .bashrc: 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/.mujoco/mujoco200/bin

But I’ve added environment variables to ~ /. Bashrc

Solution:

Finally, the error reporting is solved by manually adding environment variables for the current operating environment:

In the menu bar -> Run -> Edit Configurations -> Add the corresponding environment variables to environment variables

Name Value
LD_ LIBRARY_ PATH $LD_ LIBRARY_ PATH:/root/.mujoco/mujoco200/bin

 

[Solved] Pycharm Use pip Error: Script file ‘D:\Anaconda3\envs\pytorch\Scripts\pip-script.py‘ is not present

Problem Description:

error reporting 1: error reporting for PIP installation: script file’d:\anaconda3\envs \ pytorch\scripts\PIP script. Py ‘is not present.
error reporting 2: PIP upgrade failed: script file’d:\anaconda3\envs\pytorch\scripts\PIP script. Py’ is not present.
as shown in the following figure:


Solution:

Baidu has had the following solutions for a long time:

# Method 1: Use the command line to go to the Anconda3\Scripts\ directory and execute the command, or if it is a virtual environment, go to the \Scripts\ directory under the virtual environment

    easy_install pip # I tried this method, but it didn't work for me 
    
# Method 2: Also go to the directory and execute the following statement

    python -m ensurepip --default-pip # Perfect solution

GPY installation error: ERROR: Could not find a version that satisfies the requirement scipy…

The following error occurs when installing GPY with PIP

ERROR: Could not find a version that satisfies the requirement scipy<1.5.0,>=1.3.0 (from GPy) (from versions: 0.8.0, 0.9.0, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.12.1, 0.13.0, 0.13.1, 0.13.2, 0.13.3, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.16.0, 0.16.1, 0.17.0, 0.17.1, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 1.0.0b1, 1.0.0rc1, 1.0.0rc2, 1.0.0, 1.0.1, 1.1.0rc1, 1.1.0, 1.2.0rc1, 1.2.0rc2, 1.2.0, 1.2.1, 1.2.2, 1.2.3)
ERROR: No matching distribution found for scipy<1.5.0,>=1.3.0 (from GPy)

Solution: use PIP3

pip3 install GPy

Python Error: SyntaxError: ‘break‘ outside loop

report errors:

SyntaxError: 'break' outside loop

Break can only be used in a while loop or a for loop. If it is used in an if conditional statement, an error will be reported: syntax error: ‘break’ outside loop. However, if the if conditional statement is nested inside a while loop or a for loop,
if you do not pay attention to the format when corresponding to while, an error will also be reported

Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]

Error:
prompt when opening pycharm: invalid python sdk.
The cmd appears as: Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding;
Error message:
Python path configuration:
PYTHONHOME = ‘C:\PythonHome’
PYTHONPATH = ‘C:\PythonPath’
program name = ‘D:\Python38\python.exe’
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = ‘D:\Python38\python.exe’
sys.base_prefix = ‘C:\PythonHome’
sys.base_exec_prefix = ‘C:\PythonHome’
sys.executable = ‘D:\Python38\python.exe’
sys.prefix = ‘C:\PythonHome’
sys.exec_prefix = ‘C:\PythonHome’
sys.path = [
‘C:\PythonPath’,
‘D:\Python38\python38.zip’,
‘C:\PythonHome\DLLs’,
‘C:\PythonHome\lib’,
‘D:\Python38’,
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named ‘encodings’
Current thread 0x00008bd8 (most recent call first):

Configuring environment variables, no matter how they are configured, does not work.

Solution:
Tried opening the installation package directly and reinstalling it, and making changes in System Applications and Features, but none of them solved it.
I can only find python in settings-applications and features, uninstall it first, and then reinstall it.
The problem is solved, although after re-entering pycharm, the previous library needs to be reinstalled.