pudb3 and cftime incompatibility? - python-3.x

I am trying to debug a code with pudb (Python 3.10) but it imports xarray and while importing it there is an error with the cftime module. In pudb it says there is no module cftime._cftime. The exact error output is
File "src/cftime/_cftime.pyx", line 374, in init cftime._cftime
File "/home/lmod/software/SciPy-bundle/2021.10-intel-2022.00/lib/python3.10/site-packages/numpy/core/getlimits.py", line 651, in __init__
self.dtype = numeric.dtype(type(int_type))
TypeError: 'NoneType' object is not callable
Is there a way to fix this? It has happened before with other packages but I've been able to find a way not to use them, but I can't do that in this case.
Code imports every package perfectly fine without pudb. I've tried upgrading both xarray and numpy without success. I have numpy 1.22.0 and xarray 2022.9.0

Related

Numpy module only works at one of terminal or vscode [python3.10][mac m1 pro]

I'm trying to use numpy module in python 3.10
Since I use vscode, I installed numpy module in the vscode terminal at first.
Then, when I tried to test some simple numpy calculation thru my local terminal, this error occurred.
<error>
>>> import numpy as np
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module>
from . import multiarray
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/overrides.py", line 6, in <module>
from numpy.core._multiarray_umath import (
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so' (no such file), '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
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.
Please note and check the following:
The Python version is: Python3.10 from "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3"
The NumPy version is: "1.24.2"
and make sure that they are the versions you expect. Please carefully
study the documentation linked above for further help.
Original error was:
dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 0x0002): tried:
'/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need
'x86_64')),
'/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so' (no such file),
'/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need
'x86_64'))
Thus, I uninstalled numpy and re-installed it through my local terminal.
Then, I could import and use numpy well in my local terminal, but now I can't run python file including numpy in vscode with showing the error above in the vscode terminal.
So I always uninstall and reinstall numpy module to use it just because of difference of the platform. I want to use it in the both situation... what should I do?

Which Theano for PyMC3?

Disclaimer: SO is forcing me to express stdout output copied below as code. Simple quoting wouldn't allow me to post
I have a pyproject.toml file from a Proof of Concept that worked beautifully a few months ago, which includes:
[tool.poetry.dependencies]
theano = "^1.0.5"
pymc3 = "^3.9.3"
I copied this over to start extending from the Proof of Concept, and when trying to run it I get
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The installed Theano(-PyMC) version (1.0.5) does not match the PyMC3 requirements.
For PyMC3 to work, Theano must be uninstalled and replaced with Theano-PyMC.
See https://github.com/pymc-devs/pymc3/wiki for installation instructions.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
So I followed instructions -- removed theano and added Theano-PyMC3. This gave me no big alert at the beginning of the output, but failed:
File "mycode.py", line 4, in <module>
import pymc3
File "/home/user/.cache/pypoetry/virtualenvs/project-xNaK0WN7-py3.8/lib/python3.8/site-packages/pymc3/__init__.py", line 34, in <module>
if not semver.match(theano.__version__, ">=1.1.2"):
AttributeError: module 'theano' has no attribute '__version__'
I then tried adding aesara with a just-try-it scattergun mentality, and got the same error. I tried adding stock theano again on top of all the above, and got the first error again, even with Theano-PyMC3 still installed, and the Traceback ends with:
File "/home/user/.../code.py", line 4, in <module>
import pymc3
File "/home/user/.cache/pypoetry/virtualenvs/project-xNaK0WN7-py3.8/lib/python3.8/site-packages/pymc3/__init__.py", line 50, in <module>
__set_compiler_flags()
File "/home/user/.cache/pypoetry/virtualenvs/project-xNaK0WN7-py3.8/lib/python3.8/site-packages/pymc3/__init__.py", line 46, in __set_compiler_flags
current = theano.config.gcc__cxxflags
AttributeError: 'TheanoConfigParser' object has no attribute 'gcc__cxxflags'
Why would the same version pymc3 that worked just fine with theano last time now have a problem with it? The link provided (https://github.com/pymc-devs/pymc3/wiki) in the !!!! alert is virtually blank, so not helpful.

TypeError: NoneType not callable when debugging Python3 code that uses Cython in PyCharm

project
|-main.py
|-cythonCode.pyx
The main.py file imports functions from cythonCode.pyx.
Running the program regularly works just fine, but debugging it causes the following Exception:
(...)
File "<censored>/project/main.py", line 5, in <module>
from cythonCode import *
File "project/cythonCode.pyx", line 5, in init cythonCode
File "project/cythonCode.pyx", line 5, in __Pyx_PyMODINIT_FUNC PyInit_cythonCode(void)
TypeError: 'NoneType' object is not callable
What is happening? Why can't the debugger work with Cython?
In my case, the problem was that the Cython code was compiled using the linetrace=True compiler directive, which apparently the debugger does not like (why though? I have no idea). Setting it to False solves the issue.
I got my inspiration from an issue on the Cython github

PyCharm unittests: AttributeError: module 'enum' has no attribute 'IntFlag'

I have an error that only appears when running unittests inside of PyCharm.
Python 3.6.5 on OSX.
/Users/me/project/env/bin/python /Applications/PyCharm.app/Contents/helpers/pycharm/_jb_unittest_runner.py --target test_module.TestClass.test_method
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pycharm/_jb_unittest_runner.py", line 4, in <module>
from unittest import main
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/__init__.py", line 58, in <module>
from .result import TestResult
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/result.py", line 5, in <module>
import traceback
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/traceback.py", line 5, in <module>
import linecache
File "/Users/enos/patrf/api/env/lib/python3.6/linecache.py", line 11, in <module>
import tokenize
File "/Users/enos/patrf/api/env/lib/python3.6/tokenize.py", line 33, in <module>
import re
File "/Users/enos/patrf/api/env/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
This error seems related to Why Python 3.6.1 throws AttributeError: module 'enum' has no attribute 'IntFlag'?
The suggestions there don't work here.
Adding enum-compat to requirements.txt doesn't change anything.
A trivial unit test .py file that imports nothing at all still shows this problem.
There are no enum.py files in my project directory.
Happens with a clean virtualenv and a clean venv.
Everything works fine outside of PyCharm.
This only appears to happen in the one project I have that uses Graphene, which does have an enum.py, but even deleting those files has no effect. find . -name "enum.py" returns nothing.
Any PyCharm experts have an idea? I really like to run my tests inside of PyCharm and I'd love to be able to do so for this project.
I ran into this issue as well. I was able to solve it by removing the enum34 package. Even if you're using venv you need to make sure that you check all directories that the PyCharm Project Interpreter is adding to the PYTHONPATH. Just running pip uninstall enum34 may not fix the issue.
In my case, I had PyCharm loading extra directories to the PYTHONPATH and the enum34 package was included in one of them. Removing it from that directory solved the issue.

Error executing pytorch code AttributeError: 'function' object has no attribute 'Variable'

Trying to run pytorch code from github from following repo
https://github.com/jalola/improved-wgan-pytorch
The error is at the following statement in the file gan_train.py
writer.add_scalar('data/disc_cost', disc_cost, iteration)
The error is as follows
File "/home/anaconda/new_anaconda_3.5/lib/python3.6/site-packages/tensorboardX/writer.py", line 272, in add_scalar
self.file_writer.add_summary(scalar(tag, scalar_value), global_step)
File "/home/anaconda/new_anaconda_3.5/lib/python3.6/site-packages/tensorboardX/summary.py", line 86, in scalar
scalar = makenp(scalar)
File "/home/anaconda/new_anaconda_3.5/lib/python3.6/site-packages/tensorboardX/x2num.py", line 15, in makenp
return pytorch_np(x, modality)
File "/home/anaconda/new_anaconda_3.5/lib/python3.6/site-packages/tensorboardX/x2num.py", line 24, in pytorch_np
if isinstance(x, torch.autograd.variable.Variable):
AttributeError: 'function' object has no attribute 'Variable'
Any ideas, I am not very proficient in pytorch. It seems something is wrong with the tensorboard API.
Thanks a lot.
Shan
This seems to be a version issue, the line:
torch.autograd.variable.Variable
works with PyTorch 0.3.1 but not with version 0.4.0, then it throws the same error you have. So I guess you're using version 0.4.0.
(In version 0.4.0 the classes Tensor and Variable got merged, so Variables are not needed any longer.)
If so, using version 0.3.1 will probably solve your problem.
This is tensorboardX version error
you need change torch.autograd.variable.Variable to torch.autograd.Variable in /home/anaconda/new_anaconda_3.5/lib/python3.6/site-packages/tensorboardX/x2num.py
. its works for me.
more info https://github.com/lanpa/tensorboardX/commit/c5189bdb019085841dbfeeb457b1f6682c7dbfbf

Resources