Dlaczego nie działa załądownaie modułu

Dlaczego nie działa załądownaie modułu
Marius.Maximus
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 2200
0

Chciałem uruchomić zapisany Notebook i juz na samym początku mam problemy:

Nie działa mi import tensorflow as tf

Co zrobiłem wczesnijej:

  1. Zainstalowałem anaconda
  2. conda create -n tf tensorflow
  3. conda activate tf
  4. profilaktycznie jeszcze raz conda install tensorflow ale wszystko juz było zainstalowane
  5. jupyter notebook
  6. w przegladarce nowy dokument Notebook
  7. import numpy as np bez problemu
  8. import tensorflow as tf
Kopiuj
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[6], line 1
----> 1 import tensorflow as tf

ModuleNotFoundError: No module named 'tensorflow'

9 ) to eksperymentuje w Notebook

Kopiuj
import sys
print(sys.version)
3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:17:27) [MSC v.1929 64 bit (AMD64)]

!pip list

Package                      Version
---------------------------- ---------
absl-py                      2.1.0
aiohappyeyeballs             2.4.3
aiohttp                      3.10.5
aiosignal                    1.2.0
astunparse                   1.6.3
async-timeout                4.0.3
attrs                        24.2.0
blinker                      1.6.2
Brotli                       1.0.9
cachetools                   5.3.3
certifi                      2024.8.30
cffi                         1.17.1
charset-normalizer           3.3.2
click                        8.1.7
colorama                     0.4.6
cryptography                 41.0.3
flatbuffers                  24.3.25
frozenlist                   1.5.0
gast                         0.4.0
google-auth                  2.29.0
google-auth-oauthlib         0.4.4
google-pasta                 0.2.0
grpcio                       1.48.2
h5py                         3.12.1
idna                         3.7
keras                        2.10.0
Keras-Preprocessing          1.1.2
libclang                     18.1.1
Markdown                     3.4.1
MarkupSafe                   2.1.3
mkl_fft                      1.3.11
mkl_random                   1.2.8
mkl-service                  2.4.0
multidict                    6.1.0
numpy                        1.26.4
oauthlib                     3.2.2
opt-einsum                   3.3.0
packaging                    24.1
pip                          24.2
propcache                    0.2.0
protobuf                     3.19.6
pyasn1                       0.4.8
pyasn1-modules               0.2.8
pycparser                    2.21
PyJWT                        2.9.0
pyOpenSSL                    23.2.0
PySocks                      1.7.1
requests                     2.32.3
requests-oauthlib            2.0.0
rsa                          4.7.2
scipy                        1.14.1
setuptools                   75.1.0
six                          1.16.0
tensorboard                  2.10.0
tensorboard-data-server      0.6.1
tensorboard-plugin-wit       1.8.1
tensorflow                   2.10.0
tensorflow-estimator         2.10.0
tensorflow-io-gcs-filesystem 0.31.0
termcolor                    2.1.0
typing_extensions            4.11.0
urllib3                      2.2.3
Werkzeug                     3.0.6
wheel                        0.44.0
win-inet-pton                1.1.0
wrapt                        1.14.1
yarl                         1.18.0

!conda info


     active environment : tf
    active env location : d:\anaconda3\envs\tf
            shell level : 2
       user config file : C:\Users\m\.condarc
 populated config files : d:\anaconda3\.condarc
                          C:\Users\m\.condarc
          conda version : 24.9.2
    conda-build version : 24.9.0
         python version : 3.12.7.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=skylake
                          __conda=24.9.2=0
                          __cuda=12.6=0
                          __win=0=0
       base environment : d:\anaconda3  (writable)
      conda av data dir : d:\anaconda3\etc\conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : d:\anaconda3\pkgs
                          C:\Users\m\.conda\pkgs
                          C:\Users\m\AppData\Local\conda\conda\pkgs
       envs directories : d:\anaconda3\envs
                          C:\Users\m\.conda\envs
                          C:\Users\m\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/24.9.2 requests/2.32.3 CPython/3.12.7 Windows/11 Windows/10.0.26100 solver/libmamba conda-libmamba-solver/24.9.0 libmambapy/1.5.8 aau/0.4.4 c/. s/. e/.
          administrator : False
             netrc file : None
           offline mode : False

Widzę ze coś jest namotana z wersjami python-a
srodowisko base ma wersje 3.12.7
srodowisko tf ma wersje 3.10.13 (w tej wersji jest zainstalowany tensorflow)
a jupyter.exe notebook uruchomiony z "tf" ma python z base

srodowisko base

Kopiuj
(base) C:\Users\max>where python
d:\anaconda3\python.exe

(base) C:\Users\max>d:\anaconda3\python.exe --version
Python 3.12.7

(base) C:\Users\max>d:\anaconda3\python.exe
Python 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:17:27) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
>>>

a potem srodowisko tf

Kopiuj
(base) C:\Users\max>conda activate tf

(tf) C:\Users\max>where python
d:\anaconda3\envs\tf\python.exe

(tf) C:\Users\max>d:\anaconda3\envs\tf\python.exe --version
Python 3.10.13

(tf) C:\Users\max>d:\anaconda3\envs\tf\python.exe
Python 3.10.13 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:15:57) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>>
Kopiuj
(tf) C:\Users\max>D:\anaconda3\Scripts\jupyter.exe notebook
[W 2024-11-30 15:55:10.007 ServerApp] A `_jupyter_server_extension_points` function was not found in jupyter_lsp. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[W 2024-11-30 15:55:10.363 ServerApp] A `_jupyter_server_extension_points` function was not found in notebook_shim. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[I 2024-11-30 15:55:11.399 ServerApp] Extension package panel.io.jupyter_server_extension took 1.0372s to import
[I 2024-11-30 15:55:11.399 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2024-11-30 15:55:11.409 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2024-11-30 15:55:11.420 ServerApp] jupyterlab | extension was successfully linked.
[I 2024-11-30 15:55:11.420 ServerApp] notebook | extension was successfully linked.
[I 2024-11-30 15:55:11.838 ServerApp] notebook_shim | extension was successfully linked.
[I 2024-11-30 15:55:11.838 ServerApp] panel.io.jupyter_server_extension | extension was successfully linked.
[I 2024-11-30 15:55:11.899 ServerApp] notebook_shim | extension was successfully loaded.
[I 2024-11-30 15:55:11.899 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2024-11-30 15:55:11.899 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2024-11-30 15:55:11.910 LabApp] JupyterLab extension loaded from D:\anaconda3\Lib\site-packages\jupyterlab
[I 2024-11-30 15:55:11.910 LabApp] JupyterLab application directory is D:\anaconda3\share\jupyter\lab
[I 2024-11-30 15:55:11.910 LabApp] Extension Manager is 'pypi'.
[I 2024-11-30 15:55:12.145 ServerApp] jupyterlab | extension was successfully loaded.
[I 2024-11-30 15:55:12.156 ServerApp] notebook | extension was successfully loaded.
[I 2024-11-30 15:55:12.160 ServerApp] panel.io.jupyter_server_extension | extension was successfully loaded.
[I 2024-11-30 15:55:12.160 ServerApp] The port 8888 is already in use, trying another port.
[I 2024-11-30 15:55:12.160 ServerApp] Serving notebooks from local directory: C:\Users\max
[I 2024-11-30 15:55:12.160 ServerApp] Jupyter Server 2.14.1 is running at:
[I 2024-11-30 15:55:12.160 ServerApp] http://localhost:8889/tree?token=1fd65fb6cfc8fddc68ef0461dc380c8646247affc7569b36
[I 2024-11-30 15:55:12.160 ServerApp]     http://127.0.0.1:8889/tree?token=1fd65fb6cfc8fddc68ef0461dc380c8646247affc7569b36
[I 2024-11-30 15:55:12.160 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2024-11-30 15:55:12.301 ServerApp]

    To access the server, open this file in a browser:
        file:///C:/Users/max/AppData/Roaming/jupyter/runtime/jpserver-26460-open.html
    Or copy and paste one of these URLs:
        http://localhost:8889/tree?token=1fd65fb6cfc8fddc68ef0461dc380c8646247affc7569b36
        http://127.0.0.1:8889/tree?token=1fd65fb6cfc8fddc68ef0461dc380c8646247affc7569b36
[I 2024-11-30 15:55:12.831 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
[W 2024-11-30 15:55:14.295 ServerApp] 404 GET /api/kernels/e0285d16-30b0-4487-b226-160bf589971f?1732978513979 (127.0.0.1): Kernel does not exist: e0285d16-30b0-4487-b226-160bf589971f
[W 2024-11-30 15:55:14.295 ServerApp] wrote error: 'Kernel does not exist: e0285d16-30b0-4487-b226-160bf589971f'
    Traceback (most recent call last):
      File "D:\anaconda3\Lib\site-packages\tornado\web.py", line 1790, in _execute
        result = await result
                 ^^^^^^^^^^^^
      File "D:\anaconda3\Lib\site-packages\jupyter_server\auth\decorator.py", line 73, in inner
        return await out
               ^^^^^^^^^
      File "D:\anaconda3\Lib\site-packages\jupyter_server\services\kernels\handlers.py", line 75, in get
        model = await ensure_async(km.kernel_model(kernel_id))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "D:\anaconda3\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 501, in kernel_model
        self._check_kernel_id(kernel_id)
      File "D:\anaconda3\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 532, in _check_kernel_id
        raise web.HTTPError(404, "Kernel does not exist: %s" % kernel_id)
    tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: e0285d16-30b0-4487-b226-160bf589971f)
[W 2024-11-30 15:55:14.299 ServerApp] 404 GET /api/kernels/e0285d16-30b0-4487-b226-160bf589971f?1732978513979 (dc63a451962f47ea80eba43a88e8e932@127.0.0.1) 6.02ms referer=http://localhost:8889/notebooks/Untitled1.ipynb
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
[W 2024-11-30 15:55:21.202 ServerApp] 404 GET /api/kernels/b6486170-7def-437b-993f-877d48dbedae?1732978521199 (127.0.0.1): Kernel does not exist: b6486170-7def-437b-993f-877d48dbedae
[W 2024-11-30 15:55:21.203 ServerApp] wrote error: 'Kernel does not exist: b6486170-7def-437b-993f-877d48dbedae'
    Traceback (most recent call last):
      File "D:\anaconda3\Lib\site-packages\tornado\web.py", line 1790, in _execute
        result = await result
                 ^^^^^^^^^^^^
      File "D:\anaconda3\Lib\site-packages\jupyter_server\auth\decorator.py", line 73, in inner
        return await out
               ^^^^^^^^^
      File "D:\anaconda3\Lib\site-packages\jupyter_server\services\kernels\handlers.py", line 75, in get
        model = await ensure_async(km.kernel_model(kernel_id))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "D:\anaconda3\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 501, in kernel_model
        self._check_kernel_id(kernel_id)
      File "D:\anaconda3\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 532, in _check_kernel_id
        raise web.HTTPError(404, "Kernel does not exist: %s" % kernel_id)
    tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: b6486170-7def-437b-993f-877d48dbedae)
[W 2024-11-30 15:55:21.204 ServerApp] 404 GET /api/kernels/b6486170-7def-437b-993f-877d48dbedae?1732978521199 (dc63a451962f47ea80eba43a88e8e932@127.0.0.1) 2.36ms referer=http://localhost:8889/notebooks/Untitled.ipynb
[W 2024-11-30 15:55:23.119 ServerApp] 404 GET /api/kernels/838a4b39-3f79-458c-a4c7-21606f4c7443?1732978523118 (127.0.0.1): Kernel does not exist: 838a4b39-3f79-458c-a4c7-21606f4c7443
[W 2024-11-30 15:55:23.119 ServerApp] wrote error: 'Kernel does not exist: 838a4b39-3f79-458c-a4c7-21606f4c7443'
    Traceback (most recent call last):
      File "D:\anaconda3\Lib\site-packages\tornado\web.py", line 1790, in _execute
        result = await result
                 ^^^^^^^^^^^^
      File "D:\anaconda3\Lib\site-packages\jupyter_server\auth\decorator.py", line 73, in inner
        return await out
               ^^^^^^^^^
      File "D:\anaconda3\Lib\site-packages\jupyter_server\services\kernels\handlers.py", line 75, in get
        model = await ensure_async(km.kernel_model(kernel_id))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "D:\anaconda3\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 501, in kernel_model
        self._check_kernel_id(kernel_id)
      File "D:\anaconda3\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 532, in _check_kernel_id
        raise web.HTTPError(404, "Kernel does not exist: %s" % kernel_id)
    tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 838a4b39-3f79-458c-a4c7-21606f4c7443)


lion137
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 5023
1

Ale chaos, ja bym spróbował od początku, deaktywuj to conda base, utwórz nowe, czyste środowisko:

Kopiuj
~ conda create --name <name> python=<python_version> --no-default-packages
~ conda activate <name>

Teraz poinstaluj wszystko co potrzebujesz i zobacz czy działa, wersje, etc.

Marius.Maximus
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 2200
1

trafiony zatopiony

Kopiuj
conda create --name aa2 python=3.10 --no-default-packages
conda activate aa2
conda install tensorflow
conda install -c conda-forge notebook
jupyter notebook

ewentualnie troche inna końcówka aby miec JupyterLab zamiast Jupyter Notebook

Kopiuj
conda install -c conda-forge jupyterlab
jupyter lab

wersja 3.10 bo nie chciało działać 3.11
ale nie wiem jaka wersja jest najlepsza/optymalna , na razie to co chciałem sprawdzić mi działa

Dziękuje !

lion137
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 5023
0

jaka wersja jest najlepsza/optymalna

To zależy, imo, jakich bibliotek używasz, (bo pewnie jakąś nakładkę na tensorflow dasz), trzeba zobaczyć do dokumnetacji.

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.