Window10 : cannot import name 'as_tensor'


(win supanwanid) #1

Window10 : cannot import name ‘as_tensor’

Just setting fastai 0.7 in my Window10 Notebook (Not on cloud since I will just do only the cpu things in my notebook)
Here’s all of the step I use. (Studying Introduction to Machine Learning for Coders)

  1. Basic Environment Setup in Window10
    Fastai v0.7 install issues thread

     git clone https://github.com/fastai/fastai.git
     cd fastai
     conda env create -f environment-cpu.yml
     conda activate fastai-cpu
     jupyter notebook
    
  2. No module named ‘fastai’
    I open lesson1-rf jupyter and follow along the first lesson ML. However, I encountered the problem on the line

     from fastai.imports import *
     from fastai.structured import *
    
     No module named ‘fastai’
    

Error: No module named 'fastai' works out, so I insert the code

import sys
sys.path.append ('../../')

above from fastai…

  1. No module named ‘dataclasses’
    ModuleNotFoundError: No module named 'dataclasses'
    So in the fastai-cpu environment, I conda install in the anaconda prompt

conda install -c conda-forge dataclasses

It solve this issue! Great!

  1. No module named ‘fastprogress’
    https://github.com/fastai/fastprogress

conda install -c fastai fastprogress

In the anaconda prompt, and it solved this issue :slight_smile:

5. ImportError: cannot import name 'as_tensor’

Now, I hit the wall because in the forum and google include only for google colab and pytorch torchtext doesn’t have conda install for window
https://anaconda.org/derickl/torchtext

In the forums the thread are
ImportError: cannot import name 'as_tensor'? ->google colab
Fastai v0.7 install issues thread ->google colab

So from my perspective, it looks like my issue is not shown in the forum yet so I decided to post.

Now after this is what I have done so far in anaconda prompt :

(fastai-cpu) C:\Users\winsu>pip install torchtext==0.2.3
Requirement already satisfied: torchtext==0.2.3 in c:\users\winsu\anaconda3\envs\fastai-cpu\lib\site-packages (0.2.3)
Requirement already satisfied: requests in c:\users\winsu\anaconda3\envs\fastai-cpu\lib\site-packages (from torchtext==0.2.3) (2.19.1)
Requirement already satisfied: tqdm in c:\users\winsu\anaconda3\envs\fastai-cpu\lib\site-packages (from torchtext==0.2.3) (4.26.0)
Requirement already satisfied: idna<2.8,>=2.5 in c:\users\winsu\anaconda3\envs\fastai-cpu\lib\site-packages (from requests->torchtext==0.2.3) (2.7)
Requirement already satisfied: urllib3<1.24,>=1.21.1 in c:\users\winsu\anaconda3\envs\fastai-cpu\lib\site-packages (from requests->torchtext==0.2.3) (1.23)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\winsu\anaconda3\envs\fastai-cpu\lib\site-packages (from requests->torchtext==0.2.3) (2018.10.15)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\winsu\anaconda3\envs\fastai-cpu\lib\site-packages (from requests->torchtext==0.2.3) (3.0.4)
thinc 6.10.0 requires pathlib<2.0.0,>=1.0.0, which is not installed.
spacy 2.0.4 requires pathlib, which is not installed.
pexpect 4.6.0 requires ptyprocess>=0.5, which is not installed.
msgpack-numpy 0.4.3.2 requires msgpack>=0.3.0, which is not installed.
mkl-random 1.0.1 requires cython, which is not installed.
distributed 1.23.3 requires msgpack, which is not installed.
spacy 2.0.4 has requirement msgpack-numpy==0.4.1, but you'll have msgpack-numpy 0.4.3.2 which is incompatible.
spacy 2.0.4 has requirement regex==2017.4.5, but you'll have regex 2017.11.9 which is incompatible.
spacy 2.0.4 has requirement thinc<6.11.0,>=6.10.1, but you'll have thinc 6.10.0 which is incompatible.
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Since there is no conda install torchtext (only Mac could use conda).
I just tried pip and it shown errors like that which I don’t particularly want to reinstall/downgrade to the specific version indicated in the prompt.
Since I don’t know whether the current version will be needed anywhere else.

Just a side note:

import sys
print(sys.path)

Shows
['', 'C:\\Users\\winsu\\Anaconda3\\envs\\fastai-cpu\\python36.zip', 'C:\\Users\\winsu\\Anaconda3\\envs\\fastai-cpu\\DLLs', 'C:\\Users\\winsu\\Anaconda3\\envs\\fastai-cpu\\lib', 'C:\\Users\\winsu\\Anaconda3\\envs\\fastai-cpu', 'C:\\Users\\winsu\\Anaconda3\\envs\\fastai-cpu\\lib\\site-packages', 'C:\\Users\\winsu\\Anaconda3\\envs\\fastai-cpu\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\winsu\\.ipython', '../../', '../../', '../../', '../../']


(Stas Bekman) #2

Please try again following the windows install instructions:


(Alexey Goloviznin) #3

Sorry, but if i not have GPU - what should i do? I have the same issues like the topic started while it worked some time ago!


(Alexey Goloviznin) #4

Wow, just resolved it - the problem because i run JN from fastai folder - just move away and it works! Weird error and if I wouldn’t have a bat file for activation and changing working folder I wouldn’t find a solution!!!


(Akshay Dangare) #5

@AirVetra Thanks for the solution! worked for me.
Just to clarify the above solution -

the problem because i run JN from fastai folder - just move away and it works!

DO NOT keep your jupyter notebook in the main “fastai” folder (where you cloned the repo), instead move/copy it to a previous folder or anywhere else. (make sure to take the data folder with the dogcat images along with it as well)