joelgrus / data-science-from-scratch

code for Data Science From Scratch book
MIT License
8.63k stars 4.5k forks source link

how do I install the linear_algebra library? #1

Closed AntArch closed 9 years ago

AntArch commented 9 years ago

I've got your book. I'm working/skimming through it. I've hit a brick wall.

in your Readme.md you have the following snippet

from linear_algebra import distance, vector_mean
v = [1, 2, 3]
w = [4, 5, 6]
print distance(v, w)
print vector_mean([v, w])

This throws the following error:

ImportError: No module named linear_algebra

Where is the _linearalgebra library from? I've got a feeling it should have something to do with numpy

For info I'm running python 2.7 using the anaconda stack

joelgrus commented 9 years ago

So the short answer is that it's not really set up as a library that's "installed", it's just a bunch of files that you can import, but you have to already be in their directory:

  1. Download the files somewhere on your computer, then either 2a. start IPython from the "code" directory, or 2b. start IPython and cd to the "code" directory

i.e. if you download the whole repo to c:\data-science-from-scratch, then in IPython you'd do

In [1]: cd c:/data-science-from-scratch/code

In [2]: from linear_algebra import vector_add

Let me know if you still can't get it to work.

ghost commented 7 years ago

I'm on IPython entering \Users\Tristen\Documents\data-science-from-scratch\code but it's not working

jocagarcia commented 5 years ago

I saved the module to my local drive and did the following in the code: import sys sys.path.append ('C:\My-Data\Python') # Windows directory I used

Then you can do the import

jocagarcia commented 5 years ago

Sorry, use double \ instead of a single . Should look like:

felix4webscience commented 5 years ago

Hey @jocagarcia, I have the same current problem. How did you solve it? How should it look like? You just wrote: "Should look like: ..." but nothing else.

So I am working on my Win10 Desktop Computer I am using ipython console sometimes in combination with spyder and sometimes just with the notepadd++ distribution... Last but not least I am using Python 2.7 on Anaconda. I' ve downloaded the LinearAlgebra directory here: https://pypi.org/project/LinearAlgebra/#files I was able to install it at the Anaconda prompt but it is not found by my environments. Thus I copied the zipped file to my 2.7 python anaconda lib, where I found all the other inside such as matplotlib and so on... this also did not work... As I am able to open the single file with all the definitions, I was thinking about just put them into the code manually :-(. But I have no idea...

Any help would be great. Thx

jocagarcia commented 5 years ago

Hi,

After you download the module to your drive, it the Python distribution used by Anaconda will not be able to find it. You can either add the directory to the path or, as I did to avoid changing the path for everything, you can add it to the path at runtime. The way you do that in Python is: import sys sys.path.append ('C:\My-Data\Python') # Windows directory I used, replace with yours but use double back slash "\". Then you can import it by name

image

felix4webscience commented 5 years ago

Hi,

thank you.

Sobitan commented 5 years ago

Hello Guyz, Also got the 2nd edition of the book and its really been an amazing read and trying to follow through all the examples in the various chapters but I am having a similar issue as mentioned above. I don't know if anyone could help advise on another approach besides the one mentioned above. I tried it but still got the error message. Any help would be greatly appreciated. Thanks outlier_scatterplot

joelgrus commented 5 years ago

you need the file linear_algebra.py containing the code from the "Linear Algebra" chapter.

if you download the code from this repo you'll have it (and all the similar files)

Sobitan commented 5 years ago

Yes that's absolutely correct just did that and it resolved the issue. Thanks for the quick response and help. Really great book and learning a lot

rickhuffpm commented 4 years ago

Thank you for the well-written, well-edited book (second edition). I am running into a similar challenge mentioned by users above - ModuleNotFoundError: No module named 'linear_algebra'. Admittedly, I am more familiar with Python than the managing directories. I use Anaconda and Python 3. When I install scratch or linear algebra (using Anaconda prompt) in my personal user directory, the Anaconda prompt says the requirement is already satisfied.

I have tried the a couple directories including my personal user directory. Here is the most recent attempt.

import sys sys.path.append ('c:\Users\...\anaconda3\lib\site-packages (1.4.1)') from linear_algebra import sum_of_squares, dot

Sobitan commented 4 years ago

Hey @rickhuffpm, Getting the code from this link of this git directory solved my issue (https://github.com/joelgrus/data-science-from-scratch) Once you download the linear_algebra file from the directory and add it to your code base and it’s well referenced the error should be resolved . Good luck 👍🏿