Korean, Edit

Python Troubleshooting [01-20]

Higher category : 【Python】 Python Table of Contents



1. ERROR: Could not find a version that satisfies the requirement cv2 (from versions: none) ERROR: No matching distribution found for cv2

Solution (package): pip install opencv-python or (for Python 3) pip3 install opencv-python



2. ModuleNotFoundError: No module named ‘skimage’

Solution (package): pip install scikit-image



3. AttributeError: module ‘tensorflow’ has no attribute ‘get_default_graph’

Cause: Incompatibility between Python version and tensorflow version

Solution (package): Create a new environment

conda create --name [MY_ENV] python=3.6
activate [MY_ENV]
pip install tensorflow==1.14.0
pip install keras==2.2.4



4. ERROR: Could not build wheels for h5py, statsmodels, which is required to install pyproject.toml-based projects

Problem: This error occurred while installing scanpy with pip install scanpy on an M1 MacBook

Solution (package): Visit https://www.anaconda.com/products/individual#macos, install Anaconda, and then execute the following:

conda install h5py
pip install scanpy

Reference Site



5. ImportError: cannot import name ‘BatchNormalization’ from ‘keras.layers.normalization’

Solution 1 (package): Reinstall tensorflow and keras

Example 1: Install tensorflow==1.14.0 and keras==2.2.4 separately.

Example 2: If you had tensorflow==2.8.0, downgrade it to tensorflow==2.4.3. In this case, keras will be installed naturally under tensorflow.

Solution 2 (grammar): Replace ‘from keras.layers import BatchNormalization’ with ‘from tensorflow.keras.layers import BatchNormalization’ (Failed)

Reference Site

Solution 3 (others): If the problem persists even after reinstalling tensorflow and keras

① Analysis of the problem

○ The library should originally be found in the following location:

C:\users\sun\anaconda3\envs\tensorflow\lib\site-packages\keras\layers\normalization

○ However, in the case of the above error, the library was found in the following location:

C:\users\sun\appdata\local\programs\python\python39\lib\site-packages\keras\layers\normalization

② How to resolve it successfully by replacing the files under the appdata directory with the files under the anaconda3 directory (Successful)

③ After moving the files, activate the corresponding virtual environment and run ‘pip install jupyter’



6. AttributeError: module ‘skimage.draw’ has no attribute ‘circle’

Solution 1 (package): The issue can be resolved by downgrading scikit-image’s version

pip uninstall scikit-image
pip install scikit-image==0.18.3

① Even if it seems to be a scikit-image version issue, downgrading may not resolve the above error

Solution 2 (grammar): Instead of skimage.draw.circle, use skimage.draw.ellipse (Adopted)



7. ValueError: Could not interpret optimizer identifier: <tensorflow.python.keras.optimizer_v2.adam.Adam object at 0x000001B71092D5C8>

Cause: Mixing keras and tensorflow.keras, which are different packages

Solution (grammar):

### before ###
model.compile(loss=squared_error, optimizer=Adam(lr=lr))

### after ###
from keras.optimizers import adam
opt = adam(lr = lr)
model.compile(loss=squared_error, optimizer=opt)

Reference Site



8. ModuleNotFoundError: No module named ‘jupyter_core’

Solution (package): pip install jupyter



9. Access is denied.

Solution (system): Close Jupyter Notebook and related Anaconda prompts, then try again



10. ImportError: cannot import name ‘_validate_lengths’ from ‘numpy.lib.arraypad’

Solution (package): Based on the author’s experience, the issue occurs with numpy 1.16 but not with 1.15

Reference



11. ImportError: Could not find ‘cudart64_100.dll’. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 10.0 from this URL: https://developer.nvidia.com/cuda-90-download-archive

Problem: This error occurs after installing and then removing the GPU environment

Solution (others): Reinstalling the GPU environment in Python



12. InvalidVersionSpecError: Invalid version spec: =2.7

Problem: This error occurs when running conda install jupyterlab louvain ipywidgets in Anaconda3

Solution 1 (package): Execute the following code (Failed): https://github.com/conda/conda/issues/10618#issuecomment-826025918

%%bash
conda install --channel defaults conda python=3.6 --yes
conda update --channel defaults --all --yes
and in the next cell
!conda --version

Solution 2 (package): Delete the conda-forge line from the condarc config file and install packages/environments without using conda-forge (Failed): https://github.com/conda/conda/issues/10618#issuecomment-827671220

conda config --remove channels conda-forge

Solution 3 (package): This solution may differ slightly on Ubuntu, as the project was being developed on Ubuntu. (Failed)

① Installation on Linux: https://stlearn.readthedocs.io/en/latest/installation.html

② Installation on Ubuntu: https://www.howtoinstall.me/ubuntu/18-04/python3-ipywidgets/

sudo apt update
sudo apt install python3-ipywidgets



13. AttributeError: module ‘attr’ has no attribute ‘s’

Solution (package): Uninstall jupyterlab and reinstall it

pip uninstall jupyterlab
pip install jupyterlab



14. Build failed with 500. If you are experiencing the build failure after installing an extension (or trying to include previously installed extension after updating JupyterLab) please check the extension repository for new installation instructions as many extensions migrated to the prebuilt extensions system which no longer requires rebuilding JupyterLab (but uses a different installation procedure, typically involving a package manager such as ‘pip’ or ‘conda’). If you specifically intended to install a source extension, please run ‘jupyter lab build’ on the server for full output.

Problem (package): This error occurs when Bokeh is not properly installed. It appears in JupyterLab.

Solution (package): Refer to the Bokeh installation manual



15. * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.

Overview: This error occurs in Python when running plotly code with app.server.run()

Before Modification

if __name__ == '__main__':
    app.server.run()

After Modification: Set the IP address to match the development environment, which will automatically assign port 5000. If the port is not 5000, an error occurred.

if __name__ == '__main__':
    app.server.run(host='0.0.0.0')

⑷ If the port matches the development environment and you execute it, an ‘Address already in use’ error will occur.



16. ImportError: cannot import name ‘TypeGuard’ from ‘typing_extensions’

Solution (package): pip install typing-extensions --upgrade

Reference: https://stackoverflow.com/questions/69174965/cannot-import-name-typeguard-from-typing-extensions



17. ImportError: cannot import name ‘to_categorical’ from ‘keras.utils’

Solution (package): Downgrade to tensorflow==2.8.0, tensorflow==1.13.1, and keras==2.2.4



18. AttributeError: ‘Conv2D’ object has no attribute ‘outbound_nodes’

Solution (package): Standardize on tensorflow==1.13.1 and keras==2.2.4 by downgrading tensorflow==keras==2.4.3

⑵ When modifying packages, there may be conflicts reported in the Anaconda prompt, so ensure proper coordination



19. ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’

Solution (package): Standardize on tensorflow==1.13.1 and keras==2.2.4 by downgrading tensorflow==keras==2.4.3

⑵ When modifying packages, there may be conflicts reported in the Anaconda prompt, so ensure proper coordination



20. ERROR: Cannot uninstall ‘PyYAML’. It is a distutils installed project and thus we cannot accurately determine which files belong to it, which would lead to only a partial uninstall.

Before Modification: pip install cellphonedb

After Modification: pip install --ignore-installed cellphonedb



Input : 2021-12-24 23:33

results matching ""

    No results matching ""