Permission denied module importation with Spacepy - python

I need Spacepy package. I installed it carefully following these instructions with no particular problem. At the end of the installation, I did:
python
>>> import spacepy
And it worked just fine. Later on I tried to run a script which uses spacepy and I got an import error with this package. Then I did:
python
>>> import spacepy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "spacepy/__init__.py", line 329, in <module>
_read_config(rcfile)
File "spacepy/__init__.py", line 297, in _read_config
_write_defaults(rcfile, defaults)
File "spacepy/__init__.py", line 200, in _write_defaults
f = open(rcfile, 'r+t') #Avoid race condition, open for read and write
IOError: [Errno 13] Permission denied: '/home/arnaud/.spacepy/spacepy.rc'
>>>
I tried:
cd ~/.spacepy
chmod +rwx spacepy.rc
But it didn't change anything. I also tried to run python with sudo, and it does not work as well, although I have a different error:
sudo python
>>> import spacepy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/spacepy/__init__.py", line 131, in <module>
from . import datamodel
File "/usr/local/lib/python2.7/dist-packages/spacepy/datamodel.py", line 178, in <module>
from . import toolbox
File "/usr/local/lib/python2.7/dist-packages/spacepy/toolbox/__init__.py", line 48, in <module>
from spacepy import time as spt
File "/usr/local/lib/python2.7/dist-packages/spacepy/time.py", line 101, in <module>
import dateutil.parser as dup
ImportError: No module named dateutil.parser
In addition, when running python with sudo, I cannot load all the other packages (numpy, scipy, etc...). I installed python 2.7 with anaconda.
Do you know something I could try ?
I did the exact same procedure on another computer and it worked with no problem.

I figured it out. Change spacepy.rc file permissions was indeed the good solution, but I did not apply it to all users with 'a' flag. Doing:
cd ~/.spacepy
chmod a+rwx spacepy.rc
Solved the problem

Related

Error in running python file using ASE library

I am trying to run a python script using ASE library, I have installed ase (https://wiki.fysik.dtu.dk/ase/install.html)and run my python script using this library on my terminal. I have made a virtual env named 'MLC_env' and have already installed the ase library there.
There is a folder 'Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase' which got installed over there. Now the the website (https://pypi.org/project/ase/) says Add ~/ase to your $PYTHONPATH environment variable and add ~/ase/bin to $PATH (assuming ~/ase is where your ASE folder is).
I am not able to figure out what exactly I have to do? How to add this ase folder to my pythonpath? Any suggestions will be helpful.
I tried to follow this answer Permanently add a directory to PYTHONPATH? , according to this I can try doing export PYTHONPATH="${PYTHONPATH}:/my/other/path"" where ~/ase will be the full path name of the ase folder. Shall I go ahead with this? any suggestions.
Python script
from ase import Atoms
atoms = Atoms('N2')
print(atoms.positions)
Error: While trying to run the above python script
(MLC_env) (base) anshumansinha#Anshumans-MacBook-Pro-3 Q1 % python3 struct.py
Traceback (most recent call last):
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/compat/py3k.py", line 24, in <module>
import pickle5 as pickle
File "/Users/anshumansinha/.local/lib/python3.10/site-packages/pickle5/__init__.py", line 1, in <module>
from .pickle import *
File "/Users/anshumansinha/.local/lib/python3.10/site-packages/pickle5/pickle.py", line 33, in <module>
from struct import pack, unpack
File "/Users/anshumansinha/Desktop/MLC/HW1/Q1/struct.py", line 1, in <module>
from ase import Atoms
ImportError: cannot import name 'Atoms' from partially initialized module 'ase' (most likely due to a circular import) (/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module>
from . import multiarray
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/overrides.py", line 8, in <module>
from numpy.compat._inspect import getargspec
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/compat/__init__.py", line 12, in <module>
from . import py3k
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/compat/py3k.py", line 26, in <module>
import pickle
File "/Users/anshumansinha/miniforge3/lib/python3.10/pickle.py", line 33, in <module>
from struct import pack, unpack
File "/Users/anshumansinha/Desktop/MLC/HW1/Q1/struct.py", line 1, in <module>
from ase import Atoms
ImportError: cannot import name 'Atoms' from partially initialized module 'ase' (most likely due to a circular import) (/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/anshumansinha/Desktop/MLC/HW1/Q1/struct.py", line 1, in <module>
from ase import Atoms
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py", line 17, in <module>
from ase.atom import Atom
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/atom.py", line 3, in <module>
import numpy as np
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/__init__.py", line 141, in <module>
from . import core
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/__init__.py", line 49, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.10 from "/Users/anshumansinha/Desktop/MLC/MLC_env/bin/python3"
* The NumPy version is: "1.24.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: cannot import name 'Atoms' from partially initialized module 'ase' (most likely due to a circular import) (/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py)

ImportError: No module named gconf when importing dogtail

I have successfully install dogtail 0.7.1.1 on my system but when I try to
from dogtail import tree
I get this error instead
Traceback (most recent call last):
File "appstartup.py", line 9, in ?
from dogtail.procedural import *
File "/usr/lib/python2.4/site-packages/dogtail/procedural.py", line 18, in ?
import tree
File "/usr/lib/python2.4/site-packages/dogtail/tree.py", line 66, in ?
checkForA11y()
File "/usr/lib/python2.4/site-packages/dogtail/utils.py", line 185, in checkForA11y
if not isA11yEnabled(): bailBecauseA11yIsDisabled()
File "/usr/lib/python2.4/site-packages/dogtail/utils.py", line 158, in isA11yEnabled
import gconf
ImportError: No module named gconf
I have used the below command to verify that gconf is available on my system. Have anyone encountered this problem?
> gconftool-2 --version
2.16.0
pip install gconf should fix it.

Can't import numpy when venv is activated with activate_this

When I activate my venv normally, things work fine.
However, when I use the activate_this.py library to activate internally to my python script, I get:
>>> this_file='win\\CYAN\Scripts\\activate_this.py'
>>> exec(open(this_file).read(), {'__file__': this_file})
>>> import numpy
Traceback (most recent call last):
File "C:\Dropbox (CEP)\venvs\win\CYAN\Lib\site-packages\numpy\core\__init__.py", line 40, in <module>
from . import multiarray
File "C:\Dropbox (CEP)\venvs\win\CYAN\Lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
from . import overrides
File "C:\Dropbox (CEP)\venvs\win\CYAN\Lib\site-packages\numpy\core\overrides.py", line 6, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Dropbox (CEP)\venvs\win\CYAN\Lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Dropbox (CEP)\venvs\win\CYAN\Lib\site-packages\numpy\core\__init__.py", line 71, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
[LOTS of stuff about standard causes of this problem deleted ending with]
Original error was: No module named 'numpy.core._multiarray_umath'
In both cases I'm using the same python: C:\Python37\python.exe which is 64b (I ran virtualenv with -p python so the virtualenv is just a copy of that...)
ETA:
I see that there are some references from 2015 about numpy not being 64b... I assume that that's dealt with by now, because I've seen no reference to it since then... if I'm wrong, that would be good to know...
Added data: This appears to be something set up weirdly on MY computer.. when I try this on someone elses computer (set up supposedly the same way...) it works fine... Even across dropbox...
This probably has to do with the warnings I got when doing the pip install -r requirements.txt, but I'm not getting anymore so maybe there was a problem in the requirements.txt...

Passing Python3 to virtualenvwrapper throws up ImportError

I'm trying to use the virtualenvwrapper to make a python 3 based virtualenv. However,I'm when I pass the optional interpreter argument, I'm seeing this error. I'm running Ubuntu 15.04. I tried reinstalling virtualenv and virtualenvwrapper without success. Thanks for all your help!
$ mkvirtualenv scriptcutter --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I come across same issue, but after I downgrade virtualenv to 12.0.2, this problem disappears.
This is sort of a workaround for now.
Create a virtualenv using pyvenv.
# install pyvenv on Ubuntu
sudo apt-get install python3-venv
To minimize disruption in your normal workflow, pass a destination directory that is the same as the one used by virtualenvwrapper Like so,
pyvenv example ~/.virtualenvs/example
This is automatically working with workon and cdproject commands. I don't use much else that is provided by virtualenvwrapper
Hope this helps.
You can upgrade to the most recent version of virtualenv, with:
sudo pip install --upgrade https://github.com/pypa/virtualenv/archive/master.zip
virtualenv --version
# Returns 15.2.0.dev0 when I ran it
The following command then works:
mkvirtualenv scriptcutter --python=/usr/bin/python3
Apparently, the develop branch was dropped, so the URL with "develop" will no longer work. My answer was based off of #pjotr_dolphin's comment, with the URL updated.

Error while building ns-3

I am trying to install ns-3 by tarball but when I try to build with following command
./build.py --enable-examples --enable-tests
as given in manual I get following error:
Traceback (most recent call last):
File "./build.py", line 170, in <module>
sys.exit(main(sys.argv))
File "./build.py", line 111, in main
config = dom.parse(dot_config)
File "/usr/local/lib/python2.7/xml/dom/minidom.py", line 1917, in parse
from xml.dom import expatbuilder
File "/usr/local/lib/python2.7/xml/dom/expatbuilder.py", line 32, in <module>
from xml.parsers import expat
File "/usr/local/lib/python2.7/xml/parsers/expat.py", line 4, in <module>
from pyexpat import *
ImportError: /usr/local/lib/python2.7/lib-dynload/pyexpat.so: undefined symbol: PyUnicodeUCS2_DecodeUTF
I know this error is related to python but not able to resolve after doing a lot of Google search.Can anybody help me how to proceed further?
Solved:
After exhausted research I found Python for Linux default setting is UCS2.
I rebuilt Python from source using
./configure --enable-unicode=ucs4
to force compile using UCS4.
Here is the link.

Categories