python install script import error - python

I am using the anaconda python distribution and am having an issue running the script. I am using the command, 'sudo python setup.py install' on the script. Below is the a few lines of the install script (where the error seems to occur):
try:
from nisext.sexts import package_check, get_comrec_build
except ImportError:
raise RuntimeError('Need nisext package from nibabel installation'
' - please install nibabel first')
when I run 'sudo python setup.py install', I get the following error:
Traceback (most recent call last):
File "setup.py", line 23, in <module>
raise RuntimeError('Need nisext package from nibabel installation'
RuntimeError: Need nisext package from nibabel installation - please install nibabel first
This does not make any sense to me, as I have the necessary package in the current environment. When I open python using the 'python' command and manually type the line 'from nisext.sexts import package_check,get_comrec_build', the package imports fine and a new line is presented by python (indicating to my knowledge that the imports were successful). Does anybody know why this might occur? I am at a loss for why this error is being raised.

Figured it out. Am posting reply instead of deleting because it may be helpful for people new to linux as myself. Apparently, the sudo command runs in the root's environment and does not retain the virtual environment (which was the location of the packages, in my case). Therefore, the packages did not exist where python was looking for them, since it was looking in the default package location and not the virtual environment's packages.

Related

Cannot use the package "openexr" in python within Blender

I've installed the "openexr" package within my windows system. To do this, i used powershell from my blender installation folder "C:\Program Files\Blender Foundation\Blender 3.0\3.0\python" to launch the command ".\bin\python.exe -m ensurepip", for installing pip, and then "pip install openexer" to install the package.
Everything seems fine, but when I open blender and start to code with a simple
import openexr
I obtain this error:
Traceback (most recent call last):
File "\Text", line 1, in <module>
ModuleNotFoundError: No module named 'openexr'
Error: Python script failed, check the message in the system console
The module seems installed, but it's like blender cannot access it. Someone can help me? I would be extremely happy if this could work !
At the moment I tried to re-install pip or the openexr package, but the problem persist.
Also, if I try to re-install openexr, the system answer me that the package is already installed.

Python Module not found when installed with python -m pip install -e <my_package>

I am attempting to install a local directory as a python package, so as to make other modules in the package accessible to each other, similarly to how java files are able to access each other.
python -m pip list | grep sumobot returns:
sumobot 0.1 /home/pi/Documents/sumobot
However, trying to run a file in the package returns this error:
Traceback (most recent call last):
File "tests/test_motor.py", line 1, in <module>
from sumobot.robot_hardware.motor import RawMotor as Motor
ModuleNotFoundError: No module named 'sumobot'
I'd like to understand how this can be the case, as from my reading, installing with python -m pip should fix issues of wrong python versions. Also, if there is a better way to do what I am looking to do, please let me know.
If it makes a difference, I am running this on a raspberry pi zero, and the contents of my setup.py (which was placed in the same directory as my sumobot package) are as follows:
from distutils.core import setup
setup(name='sumobot',
version='0.1',
description='is a sumobot!',
packages=['sumobot'])```

I receive ModuleNotFoundError only when the package is downloaded from PyPI

I am working on a Back Up system named RunUp - Is still on a very early stage.
You can see all the source code on its GitHub page. And also, I uploaded it to PyPI, so, probably you won't have any problem to see what is happening by your self.
Well, this is the thing:
If you download the repo, move to the root, create your virtual environment and run pip install --editable . (do not omit the dot), you will see that the installation runs well and if you use runup --version it will show the output RunUp, version 0.1.dev4. Everything is OK.
But...
If you open a new console (or uninstall the package) and download it directly from PyPI with pip install runup, it will be installed without problem but when you use it (running again runup --version) it will output an error message:
Traceback (most recent call last):
File "/home/user/path/to/repo/venv/bin/runup", line 5, in <module>
from src.runup.cli import cli
ModuleNotFoundError: No module named 'src'
I don't know very well why this is happening but I may think that is related to my setuptools implementation or the directory tree. Not really sure about that.

Running numpy using anaconda and VS Code

I am trying to get VScode to work with anaconda but having issues with numpy. I have managed to get VScode to use the right python environment From VScode (ctrl+shift+P, type Python:Select Interpreter and select the appropriate option).
However, when I type "import numpy" in to my script, I get the following error message:
C:\ProgramData\Anaconda3\envs\sandpit\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:\ProgramData\Anaconda3\envs\sandpit\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\ProgramData\Anaconda3\envs\sandpit\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\ProgramData\Anaconda3\envs\sandpit\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\[NAME]\Documents\python\sandpit\hello.py", line 2, in <module>
import numpy
File "C:\ProgramData\Anaconda3\envs\sandpit\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\ProgramData\Anaconda3\envs\sandpit\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.8 from "C:\ProgramData\Anaconda3\envs\sandpit\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
I have successfully called the 'import numpy' command from the anaconda command prompt so it seems the issue is just with VS-Code?
I have also tried to reinstall numpy from the environment with the following command conda install numpy --force-reinstall but this has no effect?
Try launching VS Code from your activated conda environment. Errors like this typically come up if you managed to run code before your shell had a chance to do a conda environment activation.
There is one step more
Launch Anaconda 3 powershell
conda init cmd.exe #to allow cmd to run VScode
Lauch VScode by the hitting the command code.

using netcdf without installation

I need to use netcdf but do not have install permission for python modules. I have downloaded netcdf-0.1.2.tar.gz from here: https://pypi.python.org/simple/netcdf/ and unzipped the tar ball. I have been following this stack overflow post in an attempt to use the module but have had no luck so far:
(Python) Use a library locally instead of installing it
here is what I have tried:
Installing virtualenv:
I do not have permission to do this
python setup.py install -- user:
again, I don't have permission
running my script with netcdf as my current working directory:
I tried this as well, here are the issues I have run into:
first I went into netcdf-0.1.2 and made a new file called asdf.py
which contains the following:
import netcdf
print("testing")
running python asdf.py gives the following error:
Traceback (most recent call last):
File "asdf.py", line 1, in <module>
import netcdf
File "/.../Downloads/netcdf-0.1.2/netcdf/__init__.py", line 1, in <module>
from netcdf import *
File "/.../Downloads/netcdf-0.1.2/netcdf/netcdf.py", line 1, in <module>
from netCDF4 import Dataset, numpy
ImportError: No module named netCDF4
I'm not sure how to fix this error, any help would be greatly appreciated
in case this is somehow relevant, the version of Linux I am using is 3.2.0-23-generic
also I have numpy installed already
Easest would be to install Anaconda or Miniconda with your user rights.
Anaconda already as netCDF4installed. In case of Miniconda install with:
conda install netcdf4
If you have Python 3 installed, then you will have the venv package in the standard library, so you do not need "virtualenv" to be installed for you separately (as would be the case with Python 2). Instead use python3 -mvenv , in a similar way to how you would use virtualenv, for example:
python3 -mvenv /path/to/my_venv
or to include any non-standard packages already installed on the system:
python3 -mvenv --system-site-packages /path/to/my_venv
After that, you should be able to activate the environment and pip install packages, e.g.
source /path/to/my_venv/bin/activate # for csh use activate.csh instead
pip install netCDF4
Remember to source the activate script at run time as well as installation time:
source /path/to/my_venv/bin/activate
python
and you should then find that in your python session you have the netCDF4 package available, e.g.
import netCDF4
my_dataset = netCDF4.Dataset('myfile.nc')
Of course, substitute the actual path in place of /path/to/my_venv above.
None of this requires any root privileges.
(And as someone else has suggested, another option for you is to use conda.)
I'd also like to highlight that the package is imported using capitals
import netCDF4 as nc
This might not matter on a mac, but for Windows it is key.

Categories