0

I have written a script that depends on importing pandas and random libraries as a first step. However, when I try to run this script in python3 on a Mac computer,

I think I could just get away with using pandas and without importing numpy at all, but when I do, the same problem occurs, just with pandas instead of numpy. I get the Same ModuleNotFoundError. So there's something wrong with the way that I'm trying to import the libraries.

I'm confused because everything works fine on multiple windows machines. I can't imagine that numpy or pandas are restricted to Windows only.

This is how I'm importing the libraries.

import numpy as np
import pandas as pd
import random

I expect this to import numpy, pandas, and random without comment, but I actually get this error:

Traceback (most recent call last):
    File "pandasplay.py," line 1, in <module> 
    import numpy as np 
ModuleNotFoundError: No module named 'numpy'

Did something go wrong with installation of python three on the mac? I'm using Python 3.7.3.

  • Do you have the module directory specified in your path? – Lee Garcon Jun 22 '19 at 05:20
  • I'll check the next time I have access to the end user's computer. – Obsidian Scarlet Jun 22 '19 at 05:39
  • @LeeGarcon that would be something that looks a lot like this (?): `/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages` – Obsidian Scarlet Jun 22 '19 at 07:12
  • 1
    Did ypu `pip install pandas numpy?` – CristiFati Jun 22 '19 at 07:14
  • Can you give us the contents of your `site-packages`? – Lee Garcon Jun 22 '19 at 07:57
  • It's working now. The macs I was working on had python 2.7 installed; I wrote the program on a windows machine using python 3.7. To solve the problem, I installed python3, used `pip3 install pandas numpy` (since pip by itself was installing the modules to 2.7), and then `pip3 install xlrd`. After that, was good to go. Thanks all for your help! Not sure why this was so confusing; I think import by itself just worked on my windows machine. Also, new to python, definitely new to using across operating systems, so thanks for your patience. – Obsidian Scarlet Jun 22 '19 at 08:00

0 Answers0