网络编程
位置:首页>> 网络编程>> Python编程>> jupyter notebook 多环境conda kernel配置方式

jupyter notebook 多环境conda kernel配置方式

作者:dby_freedom  发布时间:2022-09-05 04:45:36 

标签:jupyter,notebook,conda,kernel

一直记不住在jupyter notebook配置多环境编译器技巧,今总结于此,也希望对其他小伙伴有所帮助,如果有用请点赞!

1.对windows用户,win+R,输入cmd进去进入命令行,激活环境:

jupyter notebook 多环境conda kernel配置方式

2.首先,确定自己是否安装包‘ipykernel',若是没有安装,则进行安装;已安装进行下一步。

jupyter notebook 多环境conda kernel配置方式

3.然后输入命令:

python -m ipykernel install --user --name deeplearningproject --display-name "deeplearningproject"

注:上述两个 deeplearningproject,前者是自身环境名称,不能变化;后者是在jupyter notebook的显示名称,可修改。

jupyter notebook 多环境conda kernel配置方式

4.至此,完成所有操作,输入jupyter notebook进行验证

jupyter notebook 多环境conda kernel配置方式

5.大功告成

jupyter notebook 多环境conda kernel配置方式

至此,完成所有操作。

补充知识:Python Jupyter notebook 运行 multiprocessing 跑不了的问题

最近工作中为了解决python支持多核cpu,遇到一个Jupyter notebook跑不了multiprocessing的问题。

网上找了些multiprocessing的例子,Pycharm可以跑,但是在Jupyter notebook上跑了就只有In[*],error log:

AttributeError: Can't get attribute 'task' on <module '__main__' <built-in>>

最后找到一个解决方案:把方法写到临时文件里,再读出来。


from multiprocessing import Pool
from functools import partial
import inspect

def parallal_task(func, iterable, *params):

with open(f'./tmp_func.py', 'w') as file:
   file.write(inspect.getsource(func).replace(func.__name__, "task"))

from tmp_func import task

if __name__ == '__main__':
   func = partial(task, params)
   pool = Pool(processes=8)
   res = pool.map(func, iterable)
   pool.close()
   return res
 else:
   raise "Not in Jupyter Notebook"

def long_running_task(params, id):
 # Heavy job here
 return params, id

data_list = range(8)

for res in parallal_task(long_running_task, data_list, "a", 1, "b"):
 print(res)

传送门:https://stackoverflow.com/questions/47313732/jupyter-notebook-never-finishes-processing-using-multiprocessing-python-3?r=SearchResults

来源:https://blog.csdn.net/Dby_freedom/article/details/80033762

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com