mac 系统下安装python的话,默认是python2.7的版本.如果是使用brew 安装的话,我安装不上,只能在python的官网上下载了python3.9.9的版本
zhengenyue@zhengenyuedeMacBook-Pro Versions % python3 -V Python 3.9.9
因为官网的教程是需要是python3.9的来安装,官网的教程必须使用 python 命令,而我的系统必须使用python3 才能使用,所以这里我必须
使用alias来处理
Python 2.7与Python 3.9版本的切换 使用Python 2.7时,直接将~/.bash_profile文件中3.9的版本注释掉,即 #alias python="/Library/Frameworks/Python.framework/Versions/3.9/bin/python39" #alias pip="/Library/Frameworks/Python.framework/Versions/3.8/bin/pip3.9" 使用Python 3.9时,直接将~/.bash_profile文件中3.9的版本打开,即 alias python="/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9" alias pip="/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9"
验证效果
zhengenyue@zhengenyuedeMacBook-Pro Versions % source ~/.bash_profile zhengenyue@zhengenyuedeMacBook-Pro Versions % zhengenyue@zhengenyuedeMacBook-Pro Versions % zhengenyue@zhengenyuedeMacBook-Pro Versions % python -V Python 3.9.9
zhengenyue@zhengenyuedeMacBook-Pro MindSpore % brew install --cask --appdir=/Applications docker ==> Downloading https://desktop.docker.com/mac/main/amd64/67817/Docker.dmg ######################################################################## 100.0% ==> Installing Cask docker ==> Moving App 'Docker.app' to '/Applications/Docker.app' ==> Linking Binary 'docker-compose.bash-completion' to '/usr/local/etc/bash_comp ==> Linking Binary 'docker.zsh-completion' to '/usr/local/share/zsh/site-functio ==> Linking Binary 'docker.fish-completion' to '/usr/local/share/fish/vendor_com ==> Linking Binary 'docker-compose.fish-completion' to '/usr/local/share/fish/ve ==> Linking Binary 'docker-compose.zsh-completion' to '/usr/local/share/zsh/site ==> Linking Binary 'docker.bash-completion' to '/usr/local/etc/bash_completion.d docker was successfully installed! zhengenyue@zhengenyuedeMacBook-Pro MindSpore % docker -v Docker version 20.10.8, build 3967b7d
zhengenyue@zhengenyuedeMacBook-Pro MindSpore % docker pull swr.cn-south-1.myhuaweicloud.com/mindspore/mindspore-cpu:1.5.0 1.5.0: Pulling from mindspore/mindspore-cpu f22ccc0b8772: Pull complete 3cf8fb62ba5f: Pull complete e80c964ece6a: Pull complete fa6f89187f2f: Pull complete 316424102b04: Pull complete 80e5dfed8c7b: Pull complete a81726836b6a: Pull complete e47915d7c8a7: Pull complete 0dfe6f871290: Pull complete 0c96b3e462e6: Pull complete 4cdc1a05b8fa: Pull complete 4cb5933b824a: Pull complete Digest: sha256:3e237d10ca1bde886ba032075a54bb7d8e63a315a0364e18f46d0d5652b51ca3 Status: Downloaded newer image for swr.cn-south-1.myhuaweicloud.com/mindspore/mindspore-cpu:1.5.0 swr.cn-south-1.myhuaweicloud.com/mindspore/mindspore-cpu:1.5.0 zhengenyue@zhengenyuedeMacBook-Pro MindSpore %
#{tag}对应上述表格中的标签。 docker run -it swr.cn-south-1.myhuaweicloud.com/mindspore/mindspore-cpu:{tag} /bin/bash
zhengenyue@zhengenyuedeMacBook-Pro ~ % docker exec -it be934b24274681c79f73dab6c7a1a5defd5aaaf758907b0dfc87a1f7a1959588 /bin/sh sh-4.4# sh-4.4# sh-4.4# sh-4.4# python -c "import mindspore;mindspore.run_check()" MindSpore version: 1.5.0 [WARNING] DEBUG(24,7f711a126600,python):2021-12-19-00:52:38.000.377 [mindspore/ccsrc/debug/debugger/debugger.cc:92] Debugger] Not enabling debugger. Debugger does not support CPU. The result of multiplication calculation is correct, MindSpore has been installed successfully!
#注意,这个是本地机器执行的 zhengenyue@zhengenyuedeMacBook-Pro MindSpore % docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dbd4d6043b1a swr.cn-south-1.myhuaweicloud.com/mindspore/mindspore-cpu:1.5.0 "/bin/bash" 14 minutes ago Up 14 minutes focused_mendel be934b242746 swr.cn-south-1.myhuaweicloud.com/mindspore/mindspore-cpu:1.5.0 "/bin/bash" 35 minutes ago Exited (0) 15 minutes ago charming_nash 7477771099c2 alpine/git "git clone https://g…" 48 minutes ago Exited (0) 48 minutes ago repo zhengenyue@zhengenyuedeMacBook-Pro MindSpore % zhengenyue@zhengenyuedeMacBook-Pro MindSpore % zhengenyue@zhengenyuedeMacBook-Pro MindSpore % zhengenyue@zhengenyuedeMacBook-Pro MindSpore % docker cp ./MindTest.py dbd4d6043b1a:/home/MindSpore/MindTest.py
#这个官网有给出样例,我保存到MindTest.py文件上传到docker中执行 import numpy as np import mindspore.context as context import mindspore.ops as ops from mindspore import Tensor context.set_context(mode=context.PYNATIVE_MODE, device_target="CPU") x = Tensor(np.ones([1,3,3,4]).astype(np.float32)) y = Tensor(np.ones([1,3,3,4]).astype(np.float32)) print(ops.add(x, y))
root@docker-desktop:/home/MindSpore# ls MindTest.py root@docker-desktop:/home/MindSpore# python MindTest.py #这里是shell执行后的结果 [WARNING] DEBUG(45,7f288eb19600,python):2021-12-19-01:31:20.855.491 [mindspore/ccsrc/debug/debugger/debugger.cc:92] Debugger] Not enabling debugger. Debugger does not support CPU. [[[[2. 2. 2. 2.] [2. 2. 2. 2.] [2. 2. 2. 2.]] [[2. 2. 2. 2.] [2. 2. 2. 2.] [2. 2. 2. 2.]] [[2. 2. 2. 2.] [2. 2. 2. 2.] [2. 2. 2. 2.]]]]
root@docker-desktop:/home/MindSpore# mindinsight start --port 8080 Workspace: /root/mindinsight Summary base dir: /home/MindSpore Web address: http://127.0.0.1:8080 service start state: success