Numpy fails to import except in Admin command prompt - python

I recently updated numpy on Windows using pip and encountered a strange problem. After the update when I run python from an Admin prompt and import numpy, it works fine. But when I import it from a normal non-admin prompt, I get this error:
>>> import numpy
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import numpy
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\numpy\__init__.py", line 190, in <module>
from . import add_newdocs
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\numpy\lib\__init__.py", line 9, in <module>
from .index_tricks import *
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\numpy\lib\index_tricks.py", line 12, in <module>
from . import function_base
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\numpy\lib\function_base.py", line 2489, in <module>
def corrcoef(x, y=None, rowvar=1, bias=np._NoValue, ddof=np._NoValue):
AttributeError: module 'numpy' has no attribute '_NoValue'
And when I tried again it changes to
>>> import numpy
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import numpy
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\numpy\__init__.py", line 190, in <module>
from . import add_newdocs
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\numpy\lib\__init__.py", line 9, in <module>
from .index_tricks import *
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\numpy\lib\index_tricks.py", line 6, in <module>
import numpy.core.numeric as _nx
AttributeError: module 'numpy' has no attribute 'core'
All the library files are in the file system although it sounds like it is unable to find numpy.core.
One possibly relevant fact is that python is installed in C:\Program Files (x86)\Python 3.5 rather than in the root directory. (This is the default install location as of 3.5, but has caused minor problems before.) I wonder if there could be a problem with file or directory permissions?
Also I tried reinstalling and even downgrading back to 1.10.4 (using the binary here and the problem persisted, although it wasn't there before the upgrade, and I installed it from the same source.
Any ideas on what the issue is?

Related

How Do I get rid of this error:Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Program?

I keep trying to start my python backend with uvicorn main:app --reload but I keep getting this error:
INFO: Will watch for changes in these directories: ['C:\\Users\\darkg\\OneDrive\\Desktop\\loginpage\\FastAP_BackEnd\\books']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [532] using StatReload
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\multiprocessing\spawn.py", line 126, in _main
self = reduction.pickle.load(from_parent)
File "C:\Users\darkg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\uvicorn\__init__.py", line 1, in <module>
from uvicorn.config import Config
File "C:\Users\darkg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\uvicorn\config.py", line 1, in <module>
import asyncio
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 18, in <module>
import concurrent.futures
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\concurrent\futures\__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\concurrent\futures\_base.py", line 7, in <module>
import logging
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\tokenize.py", line 35, in <module>
from token import *
File "C:\Users\darkg\OneDrive\Desktop\loginpage\FastAP_BackEnd\books\.\token.py", line 5, in <module>
from . import schemas
ImportError: attempted relative import with no known parent package
I tried starting it with python -m uvicorn main:app --reload
but I get this error instead
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 146, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "C:\Users\darkg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\uvicorn\__init__.py", line 1, in <module>
from uvicorn.config import Config
File "C:\Users\darkg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\uvicorn\config.py", line 1, in <module>
import asyncio
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 18, in <module>
import concurrent.futures
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\concurrent\futures\__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\concurrent\futures\_base.py", line 7, in <module>
import logging
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\tokenize.py", line 35, in <module>
from token import *
File "C:\Users\darkg\OneDrive\Desktop\loginpage\FastAP_BackEnd\books\token.py", line 5, in <module>
from . import schemas
ImportError: attempted relative import with no known parent package
Here is the main code
from . import models
from fastapi import FastAPI
from .database import engine
from .routers import books, users,authentication
app=FastAPI()
models.Base.metadata.create_all(engine)
app.include_router(books.router)
app.include_router(users.router)
app.include_router(authentication.router)
Here is my Code File Path If that helps solve the issue :
Code File Structure
I have tried everything but cant seem to find a way to fix this . I've redowloaded python. I've reinstalled every package, ive added paths to my packages, but nothing seems to work. Any help would be greatly appreciated. I am completely lost
Python doesn't know that the directory containing your modules (including main.py) is a package, therefore it can't properly locate imports. Create an empty __init__.py file in this directory to mark it as a regular package.
A rule of thumb is to mark all your directories that contain python modules as packages with this method.
There's another type of Python packages that may make your code sometimes work: namespace packages. They don't have to contain an __init__.py file. I recommend to just avoid them, unless you understand exactly what they're for and why you need them. [Doc reference]
For a quick reference, search through the FastAPI documentation for "project file structure" (it may be called something similar).

Keras_ocr fails to import

I am trying to use Keras_ocr for a project, but I can't get it to import to my script. I am using tensorflow backend (non-gpu).
Here is the error code I am receiving:
Traceback (most recent call last):
File "C:/Users/Cameron/PycharmProjects/NN-1/Test 1.py", line 5, in <module>
import keras_ocr
File "C:\Users\Cameron\Anaconda3\envs\TensorEnv\lib\site-packages\keras_ocr\__init__.py", line 1, in <module>
from . import (detection, recognition, tools, data_generation, pipeline, evaluation, datasets,
File "C:\Users\Cameron\Anaconda3\envs\TensorEnv\lib\site-packages\keras_ocr\detection.py", line 31, in <module>
from . import tools
File "C:\Users\Cameron\Anaconda3\envs\TensorEnv\lib\site-packages\keras_ocr\tools.py", line 14, in <module>
from shapely import geometry
File "C:\Users\Cameron\Anaconda3\envs\TensorEnv\lib\site-packages\shapely\geometry\__init__.py", line 4, in <module>
from .base import CAP_STYLE, JOIN_STYLE
File "C:\Users\Cameron\Anaconda3\envs\TensorEnv\lib\site-packages\shapely\geometry\base.py", line 18, in <module>
from shapely.coords import CoordinateSequence
File "C:\Users\Cameron\Anaconda3\envs\TensorEnv\lib\site-packages\shapely\coords.py", line 8, in <module>
from shapely.geos import lgeos
File "C:\Users\Cameron\Anaconda3\envs\TensorEnv\lib\site-packages\shapely\geos.py", line 145, in <module>
_lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))
File "C:\Users\Cameron\Anaconda3\envs\TensorEnv\lib\ctypes\__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
I installed keras_ocr via pip.
This is a known issue where Keras_ocr finds the wrong DLL or can't find it at all. It can be solved simply by updating Keras_ocr or uninstalling and reinstalling keras_ocr.
Try installing Python=3.6 and the latest Tensorflow version, after that install keras_ocr.
That should work.

Is there a way to run Python code in Pydev?

I'm new to Jython and PyDev. I need to run my Python code in Eclipse.
The Python code works in Spyder/Jupyter Notebooks. When I run the programm as Jython Run/Python Run, an error pops up.
How can I solve this problem?
console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "C:\Users\Hai Mi\workspace\Camunda\learning_classify.py", line 7, in <module>
import nltk
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\nltk\__init__.py", line 129, in <module>
from nltk.collocations import *
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\nltk\collocations.py", line 40, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures, QuadgramAssocMeasures
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\nltk\metrics\__init__.py", line 16, in <module>
from nltk.metrics.scores import (
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\nltk\metrics\scores.py", line 18, in <module>
from scipy.stats.stats import betai
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\nltk\metrics\scores.py", line 18, in <module>
from scipy.stats.stats import betai
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\scipy\__init__.py", line 62, in <module>
from numpy import show_config as show_numpy_config
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\core\overrides.py", line 166
SyntaxError: unqualified exec is not allowed in function 'decorator' because it contains free variables
Looks like a similar issue was discussed here
How do I fix UnsupportedCharsetException in Eclipse Kepler/Luna with Jython/PyDev?
and adding
-Dpython.console.encoding=UTF-8
to the Run Configurations -> VM arguments could be a solution.

Not able to use Open CV in Sublime Text

I am not able to use OpenCv in Sublime text. Whenever I try to build the script, it throws this error -
File "C:\Users\ATHARVA\Desktop\Python\circle.py", line 1, in <module>
import numpy as np
File "C:\Program Files\Python\lib\site-packages\numpy\__init__.py", line 158, in <module>
from . import add_newdocs
File "C:\Program Files\Python\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Program Files\Python\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Program Files\Python\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Program Files\Python\lib\site-packages\numpy\core\__init__.py", line 74, in <module>
from numpy.testing import _numpy_tester
File "C:\Program Files\Python\lib\site-packages\numpy\testing\__init__.py", line 12, in <module>
from . import decorators as dec
File "C:\Program Files\Python\lib\site-packages\numpy\testing\decorators.py", line 6, in <module>
from .nose_tools.decorators import *
File "C:\Program Files\Python\lib\site-packages\numpy\testing\nose_tools\decorators.py", line 20, in <module>
from .utils import SkipTest, assert_warns
File "C:\Program Files\Python\lib\site-packages\numpy\testing\nose_tools\utils.py", line 15, in <module>
from tempfile import mkdtemp, mkstemp
File "C:\Program Files\Python\lib\tempfile.py", line 45, in <module>
from random import Random as _Random
ImportError: cannot import name 'Random'
[Finished in 0.2s with exit code 1]
I am not able to understand why this error is coming. Can someone help by pointing out what the problem is?
Edit:- The issue has been resolved.
You might have created a file with name Random.py / random.py find and delete it should solve the problem.
Not able to import Ope CV in Sublime Text
You didnt import cv2 (OpenCV) either. Make Sure You have installed OpenCV.
Install opencv if you havent installed it yet. From windows command line type:
pip install opencv-python
and import is as
import cv2

ABI incompatibility while importing `scipy.sparse`

I'm running a script in a virtual environment on a new machine. Running the script gives me the following traceback.
Traceback:
Traceback (most recent call last):
File "zoneMapRGB.py", line 11, in <module>
from skimage import io, color
File "/opt/python/3.6/lib/python3.6/site-packages/skimage/io/__init__.py", line 11, in <module>
from ._io import *
File "/opt/python/3.6/lib/python3.6/site-packages/skimage/io/_io.py", line 7, in <module>
from ..color import rgb2grey
File "/opt/python/3.6/lib/python3.6/site-packages/skimage/color/__init__.py", line 1, in <module>
from .colorconv import (convert_colorspace,
File "/opt/python/3.6/lib/python3.6/site-packages/skimage/color/colorconv.py", line 368, in <module>
rgb_from_xyz = linalg.inv(xyz_from_rgb)
File "/opt/python/3.6/lib/python3.6/site-packages/scipy/linalg/basic.py", line 947, in inv
a1 = _asarray_validated(a, check_finite=check_finite)
File "/opt/python/3.6/lib/python3.6/site-packages/scipy/_lib/_util.py", line 228, in _asarray_validated
import scipy.sparse
File "/opt/python/3.6/lib/python3.6/site-packages/scipy/sparse/__init__.py", line 229, in <module>
from .csr import *
File "/opt/python/3.6/lib/python3.6/site-packages/scipy/sparse/csr.py", line 15, in <module>
from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: /opt/matlab/extern/engines/python/dist/matlab/engine/glnxa64/../../../../../../../sys/os/glnxa64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /opt/python/3.6/lib/python3.6/site-packages/scipy/sparse/_sparsetools.cpython-36m-x86_64-linux-gnu.so)
It seems scipy is trying to get libstdc++.so.6 from a matlab folder instead of the python directory. Is there any way to correct this behavior?

Categories