0

I'm working with a project and somewhere down the line my I have to uninstall and reinstall numpy to fix a problem, but then this happened

Traceback (most recent call last):

   File "ori2.py", line 3, in <module>
     import numpy as np
    File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
      from . import add_newdocs
   File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
     from numpy.lib import add_newdoc
    File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>
     from .type_check import *
   File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>
     import numpy.core.numeric as _nx
   File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/core/__init__.py", line 38, in <module>
     from . import numeric
   File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/core/numeric.py", line 43, in <module>
     import pickle
   File "/home/tsoi/Documents/environments/testvenv/Traffic-rec/pickle.py", line 1
     from ~/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy import numpy as np
          ^
 SyntaxError: invalid syntax

I have also tried

import sys
sys.path.append('~/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy')

when importing numpy but the same error occured, This hasn't happened before and it's been annoying for me. This is the part of my code that I think is relevant to this problem:

from __future__ import print_function
#from comet_ml import Experiment
import numpy as np
import tensorflow as tf
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
from keras.datasets import fashion_mnist
from keras.models import Model
from keras.layers import Input, Dense
from keras.models import load_model
import cv2
import os
import glob
from os import path
import random
Tsoi Phu
  • 766
  • 2
  • 8
  • 11
  • 3
    You named a file `pickle.py` and put some weird junk in it. Delete that file; it's hiding the `pickle` module. – user2357112 Oct 09 '18 at 17:32
  • go the the terminal & run pythin an dthe manually do import and see what it say `>>> import numpy as np` this way at least you will get to know if its problem with `numpy` or its your code messing soewhere. – Karn Kumar Oct 09 '18 at 17:32
  • @user2357112 Ah it worked, I didn't know naming a .py after a module/package could be the problem, Thank you I thought it was because I installed two different version of numpy causes it. – Tsoi Phu Oct 10 '18 at 02:15

1 Answers1

1

UPDATE: Yeah you right user2357112

numpy is importing your file '/home/tsoi/Documents/environments/testvenv/Traffic-rec/pickle.py' instead of the pickle module, delete the file or rename it, then the problem should be fixed.

Lukas
  • 446
  • 3
  • 11
  • Yes I imported numpy for python3.6, but the problem was because I named a .py after a module, changing the .py name solved it but thanks for checking out my situation. – Tsoi Phu Oct 10 '18 at 02:18
  • Sorry, but i edited my answer 8 hours ago. What are you commenting to? – Lukas Oct 10 '18 at 02:45