最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Numpy 1.26.4 installation in google Collaboratory is not effective without restarting session - Stack Overflow

programmeradmin3浏览0评论

Recently, Google Collaboratory has made an upgrade of its default numpy package. The current default numpy version is 2.0.2. This causes a part of my python code to no longer be executed because of incompatibility. I realized that I need numpy 1.26.4 to be installed, so I used the following command in google colab: !pip install numpy==1.26.4 the installation seemed successful because google colab displayed the messages: Successfully uninstalled numpy-2.0.2 and Successfully installed numpy-1.26.4 However, the parts of my code that did not work with the numpy 2.0.2 still do not work. Then, I realized that when I check the installed version of numpy via the following command:

import numpy
numpy.version.version

colab still shows that it uses numpy 2.0.2.

However, if I restart the session and then check the numpy version, then the numpy version is 1.26.4 and no parts of my code have no longer the incompatibility problem.

My problem is that I cannot manually restart the session and then run the rest of the cells , every time that I run my colab notebook. I realized that I can programmatically restart the session by using the command,

import os
os.kill(os.getpid(), 9)

however I do not know how can I programmatically continue the execution of the rest of the program in the cells below, once the session is restarted. So I should find a solution for at least one of the following questions:

(1) Is there a way to make the installation of numpy 1.26.4 effective without restarting the session?

(2) Is there a way to programmatically execute the cells below a cell once the session is restarted?

(3) Is there a way to store the numpy version 1.26.4 in a virtal environment variable and store it in drive and reload and use it instead of the default google colab numpy version 2.0.2?

Recently, Google Collaboratory has made an upgrade of its default numpy package. The current default numpy version is 2.0.2. This causes a part of my python code to no longer be executed because of incompatibility. I realized that I need numpy 1.26.4 to be installed, so I used the following command in google colab: !pip install numpy==1.26.4 the installation seemed successful because google colab displayed the messages: Successfully uninstalled numpy-2.0.2 and Successfully installed numpy-1.26.4 However, the parts of my code that did not work with the numpy 2.0.2 still do not work. Then, I realized that when I check the installed version of numpy via the following command:

import numpy
numpy.version.version

colab still shows that it uses numpy 2.0.2.

However, if I restart the session and then check the numpy version, then the numpy version is 1.26.4 and no parts of my code have no longer the incompatibility problem.

My problem is that I cannot manually restart the session and then run the rest of the cells , every time that I run my colab notebook. I realized that I can programmatically restart the session by using the command,

import os
os.kill(os.getpid(), 9)

however I do not know how can I programmatically continue the execution of the rest of the program in the cells below, once the session is restarted. So I should find a solution for at least one of the following questions:

(1) Is there a way to make the installation of numpy 1.26.4 effective without restarting the session?

(2) Is there a way to programmatically execute the cells below a cell once the session is restarted?

(3) Is there a way to store the numpy version 1.26.4 in a virtal environment variable and store it in drive and reload and use it instead of the default google colab numpy version 2.0.2?

Share Improve this question asked Mar 19 at 12:21 Ben BostBen Bost 1473 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Yes, same issue. After installing 1.26.4, you need to "Restart Session" and re-import numpy. It's strange that they haven't updated their release notes yet (https://colab.research.google/notebooks/relnotes.ipynb)

You can import a requirements.txt file from Drive or anywhere that specified the version numbers (eg numpy==1.26.4), store it in the Colab file system, then do:
!pip install -r /content/requirements.txt

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论