Error:module 'torch' has no attribute 'empty'

Li_Rong: <p>Hi, I am a newbee of pytorch. When I run tutorial like follows:</p>
<p>x = torch.empty(5, 3)<br>
print(x)</p>
<p>I got errors:<br>
Error:module ‘torch’ has no attribute ‘empty’</p>
<p>I type:<br>
x = torch.tensor([5.5, 3])<br>
print(x)</p>
<p>I got error:<br>
‘module’ object is not callable</p>
<p>dose anybody could help me?</p>

11177: <p>You can use that to create tensor, you just can’t print that. You may fix that issue by reinstalling your pytorch.</p>

albanD: <p>Hi, which version of pytorch are you using?<br>
These methods have been added in 0.4 and were not present in older versions.</p>

Li_Rong: <p>I think I have installed the pytorch of version 0.4.0, but I did not uninstall the older version and I use jupyter notebook, I am not sure when I import torch from it, whats  version of the pytorch. Could you give me some suggestion?</p>

albanD: <p>You can do <code>print(torch.__version__)</code> to get the current running version.</p>

Li_Rong: <p>it shows version is 0.1.12， how I let jupyter import torch of 0.4.0?<br>
thank you…</p>

albanD: <p>You should remove and reinstall the new pytorch version for the python that jupyter uses.<br>
You can check which python is used in jupyter by running:</p>
<pre><code class="lang-auto">import sys
print(sys.executable)
</code></pre>

Li_Rong: <p>I run the command and it return me a path as follows:<br>
/home/user/anaconda3/bin/python</p>

albanD: <p>Then you need to use <code>conda</code> to install the new pytorch.</p>

Li_Rong: <p>but when I use conda to install the new version pytorch, it shows that the version of<br>
0.2.0 will be installed but not 0.4.0, as follows:</p>
<p>user@user-Server:~/anaconda3/lib/python3.5/site-packages$ conda install pytorch torchvision -c pytorch<br>
Fetching package metadata …<br>
Solving package specifications: .</p>
<p>Package plan for installation in environment /home/user/anaconda3:</p>
<p>The following NEW packages will be INSTALLED:</p>
<pre><code>pytorch:     0.2.0-py35hb1547bd_4cu80 soumith [cuda80]
torchvision: 0.1.9-py35h72e4c6f_1     soumith
</code></pre>
<p>Proceed ([y]/n)? n</p>
<p>I do not know what’s wrong</p>

albanD: <p>As answered in your other post, most certainly an old conda install.</p>

Li_Rong: <p>OK, thank you. I will try.</p>

Li_Rong: <p>I have updated conda using command as follows:<br>
conda update conda</p>
<p>and then install pytorch using command:<br>
conda install pytorch torchvision -c pytorch</p>
<p>but I got the same result. It still<br>
shows that 0.2.0 version will be installed.</p>

albanD: <p>I don’t know what it is then <img src="https://discuss.pytorch.org/images/emoji/apple/confused.png?v=5" title=":confused:" class="emoji" alt=":confused:"><br>
Someone that knows conda better might be able to help.</p>

Li_Rong: <p>any way, thank you again.</p>

ptrblck: <p>Which conda version do you have?<br>
You can check if with <code>conda --version</code>.</p>

Li_Rong: <p>I have checked conda version,which is conda 4.3.30</p>

ptrblck: <p>It looks like it’s ~6 months old (<a href="https://anaconda.org/conda-canary/conda/files?version=4.3.30">source</a>).<br>
I have <code>4.4.7</code> installed. Could you run <code>conda update conda</code> again and post the output?</p>

Li_Rong: <p>ok, I will try. thank you!</p>

Li_Rong: <p>I just run conda update conda, and I found that I still update to 4.3.30, like follows:</p>
<p>user@user-Server:~/workspace$ conda update conda<br>
Fetching package metadata …<br>
Solving package specifications: .</p>
<h1>All requested packages already installed.</h1>
<h1>packages in environment at /home/user/anaconda3:</h1>
<h1></h1>
<p>conda                     4.3.30           py35hf9359ed_0    <a href="https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free" rel="nofollow noopener">https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free</a></p>
<pre><code>I think that maybe the conda updated from a mirror website.</code></pre>