Uninstalling Python 3.10

username: Adnan_Gajraj
cooked: <p>I am trying to figure out how to go about uninstalling Python 3.10. on my computer which is a Mac OS Big Sur laptop (Version 11.6.2).</p>
<p>I am ultimately trying to install PyTorch on my laptop, but I was having trouble trying to install it via Python 3.10.</p>
<p>Would it be advisable to uninstall Python 3.10 on my computer by going to the terminal and entering the following command?</p>
<p>sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.10</p>

username: ptrblck
cooked: <p>Maybe a better approach would be to create a new virtual environment (e.g. via <code>conda</code>) and install Python=3.9 there while leaving the system 3.10 installation intact.</p>

username: Adnan_Gajraj
cooked: <p>Thanks very much for your reply. I just have one final question for now, how to go about exactly installing Python 3.9 via conda?</p>

username: ptrblck
cooked: <p>Once <code>conda</code> is installed create a new env via:</p>
<pre><code class="lang-python">conda create -n env_name python=3.9
...
conda activate env_name
</code></pre>
<p>This will install a new virtual environment with Python 3.9 and activate it afterwards. You could then install PyTorch into this environment.</p>

username: Adnan_Gajraj
cooked: <p>Hi,<br>
I’m really sorry, but I am still having a little trouble with this issue. I have followed your advice of installing conda and I got a message at the end saying that the installation was completed successfully. However, when I go into the terminal to confirm that conda has been installed correctly, it says command not found.</p>

username: ptrblck
cooked: <p>Maybe the <a href="https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html">Getting Started Guide</a> from <code>conda</code> could be helpful to get familiar with its usage and the virtual envs.</p>

username: kyoungseoun_chung
cooked: <p>Another method would be using <a href="https://github.com/pyenv/pyenv" rel="noopener nofollow ugc">pyenv</a>.</p>
<p>You can easily manage different versions of python. Once you install pyenv,</p>
<pre><code class="lang-auto">pyenv install 3.9.9.   # python version you'd like to install
</code></pre>
<p>And set that version as global</p>
<pre><code class="lang-auto">pyenv global 3.9.9
</code></pre>
<p>Then you can use python with desired version.</p>
<p>I am currently working on Mac Monetery  and work as charm.</p>

username: Adnan_Gajraj
cooked: <p>Did you use terminal to install pyenv on your Mac?</p>

username: kyoungseoun_chung
cooked: <p>Yes I am using in terminal.</p>
<p>Here is the process that I used:</p>
<p>Install <a href="https://github.com/pyenv/pyenv#homebrew-in-macos" rel="noopener nofollow ugc">pyenv</a> using homebrew.</p>
<pre><code class="lang-bash">brew update
brew install pyenv
</code></pre>
<p>After the installation, you need to set up bash environment. Since macOS uses zsh, you need to update <code>.zshrc</code> and <code>.zprofile</code> files as suggested in the GitHub page:</p>
<pre><code class="lang-bash">echo 'eval "$(pyenv init --path)"' &gt;&gt; ~/.zprofile
echo 'eval "$(pyenv init -)"' &gt;&gt; ~/.zshrc
</code></pre>
<p>Now, you can install any version python using pyenv:</p>
<pre><code class="lang-bash">pyenv install 3.9.9
</code></pre>
<p>And after that, set as global.</p>
<p>I usually setup virtual environment but it is your choice.</p>
<p>Hope this can help you.</p>

username: Adnan_Gajraj
cooked: <p>Thanks for all your help so far. I have been able to install PyTorch on my mac with your instructions, but there is just one more query I have: After installing PyTorch, how do you actually go about using PyTorch to create Deep Learning models? There are several packages that PyTorch comes installed with, so where do you go from here?</p>

username: kyoungseoun_chung
cooked: <p>Check the tutorial pages in the PyTorch website: <a href="https://pytorch.org/tutorials/" class="inline-onebox" rel="noopener nofollow ugc">Welcome to PyTorch Tutorials — PyTorch Tutorials 1.10.1+cu102 documentation</a></p>
<p>Coding process with PyTorch is just like a normal python coding.</p>
<p>PS: if you want to use tensorboard to log and/or visualise learning process, currently there is a bit of problem due to a version of <code>disutil</code> package. Check this issue: <a href="https://github.com/pytorch/pytorch/issues/69894" rel="noopener nofollow ugc">https://github.com/pytorch/pytorch/issues/69894</a></p>

username: Adnan_Gajraj
cooked: <p>Thanks I’ll definitely take a look at these tutorial pages, but which files in the Pytorch package do you click on to start a deep learning environment? Particularly, a deep learning environment for computer vision?</p>

username: kyoungseoun_chung
cooked: <p>I am a bit lost. Why are you asking for clicking something on to start a deep learning environment?</p>
<p>As far as I know, PyTorch is a library. Thus, just like another python package, you import and use their function/modules in your python code.</p>
<p>If you are talking about docker environment, then this will be another topic.</p>
<p>If you are asking about using pre-trained model, then you probably can find tutorials how to load and use them.</p>
<p>Correct me if you are talking about different things.</p>

username: Adnan_Gajraj
cooked: <p>I’m sorry I’m still a little new to python. So PyTorch comes installed with the following files:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/d/bddd78015e20668cc2216b4eda1505ba0066d12b.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/bddd78015e20668cc2216b4eda1505ba0066d12b" title="Screen Shot 2022-02-11 at 9.56.42 AM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/d/bddd78015e20668cc2216b4eda1505ba0066d12b_2_690x387.jpeg" alt="Screen Shot 2022-02-11 at 9.56.42 AM" data-base62-sha1="r5CJFmNUI1zjEnZF2mm049rnOr1" width="690" height="387" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/d/bddd78015e20668cc2216b4eda1505ba0066d12b_2_690x387.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/b/d/bddd78015e20668cc2216b4eda1505ba0066d12b_2_1035x580.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/b/d/bddd78015e20668cc2216b4eda1505ba0066d12b.jpeg 2x" data-dominant-color="263031"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2022-02-11 at 9.56.42 AM</span><span class="informations">1366×768 117 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>How do you launch the Python shell for doing the actual coding?</p>

username: kyoungseoun_chung
cooked: <p>At this point, I am not sure your question is relevant to the topic. Looks like your problem is more about python in general.</p>
<p>Anyway, I don’t know which directory you are showing on the picture but let me guess that is in <code>venv/lib/python3.9/</code> (if you created virtual environment and installed package there. And of course guess you already activated the virtual environment)</p>
<p>In python, once a library is installed, you don’t need to open the code separately. Just create any file with the extension <code>.py</code> and import the library accordingly.</p>
<p>For example, if you want to use PyTorch, create following script.</p>
<pre><code class="lang-python"># test.py

if __name__ == "__main__":
    import torch

    A = torch.rand(3, 3)  # create a 3 x 3 tensor with random numbers
    print(A) # print the tensor
</code></pre>
<p>And run the code in the terminal</p>
<pre><code class="lang-bash">python test.py # I assume your default python version is 3 not 2.
</code></pre>
<p>In this way, you can use any function/module provided by PyTorch.</p>
<p>If you want to test whether PyTorch is installed correctly or not, test in the terminal like this.</p>
<pre><code class="lang-bash">python -c "import torch; print(torch.__version__)"
</code></pre>
<p>If everything is correctly installed, you can see the version number of the PyTorch.</p>
<p>Hope this can answer some of your questions.</p>

username: Adnan_Gajraj
cooked: <p>Thanks again for your reply. I’m sorry for all the questions, I just really want to get this right. You told me to test the following command in terminal:</p>
<p>python -c “import torch; print(torch.<strong>version</strong>)”</p>
<p>and I got a version number of 1.10.2, so it appears that PyTorch is installed on my mac. However, when I try to run the following code in terminal:</p>
<p>python test.py</p>
<p>I get an error message of can’t open file, No such file or directory.</p>

username: ptrblck
cooked: <p>You would have to create the <code>test.py</code> file first before trying to execute it.<br>
As <a class="mention" href="/u/kyoungseoun_chung">@kyoungseoun_chung</a> explained, it might be helpful to check some Python tutorials first, e.g. <a href="https://docs.python.org/3/tutorial/">this one</a> (or search any [free] course) to get familiar with the programming language first.</p>