Truncated SVD attribute python - python

I'm using this tutorial code in my study.
Line to line it works well.But in the line
lsa.components_[0]
AttributeError: 'TruncatedSVD' object has no attribute 'components_'
I think the codes work well before this line, and tutorial says TruncatedSVD has atrtibute components_, but I don't know how can I solve the problem.
I'm using python 2.7 in anaconda2 environment, but I tried eclipse pydev also, same error message appeared.

Related

Attribute Error when trying to use numpy.random.choices in Google Colaboratory

I am trying to use numpy.random.choices() to generate some pseudo-random data but am getting the following error message:
AttributeError: module 'numpy.random' has no attribute 'choices'
The existing threads I can find suggest that this is a version issue: it looks like Python must be version 3.6 or higher, and there may be minimum version requirements with NumPy as well. But I am using Python 3.7.12 and NumPy 1.21.5 in my environment and still getting this error. I'm also working in a Google Colaboratory file right now, which may have something to do with the error, but I'm not sure what or why.

Problem when importing PySCIPOpt. AttributeError: type object 'pyscipopt.scip.Expr' has no attribute '__div__'

I want to use python interface for SCIP; I installed PySCIPOpt following these steps.
I'm using SCIP7, PySCIPOpt 3, and python 3.7. SCIP's interactive shell alone works well. However, when I try to import pyscipopt, I get the following error
File "src/pyscipopt/scip.pyx", line 1, in init pyscipopt.scip
AttributeError: type object 'pyscipopt.scip.Expr' has no attribute 'div'
My operating system is Linux Mint 19.2
I tried to test the installation as suggested, and I get the errors in the image
The problem seems to be an update in cython. It should be fixed in the current master of PySCIPOpt. See also https://github.com/SCIP-Interfaces/PySCIPOpt/issues/397
python is very sensitive for syntax , Like upper case etc..
so may be you try :
import PySCIPOpt instate import pyscipopt

AttributeError: dlsym(RTLD_DEFAULT, run): symbol not found - meaning

I am attempting to use the PyMultinest package. The full error text I am encountering is AttributeError:dlsym(RTLD_DEFAULT, run): symbol not found in the __getitem__() function in ctypes/__init__.py. I'll include more text and code below, but I am mostly trying to understand what this error is telling me - my Google Fu is apparently lacking, and the StackExchange questions I have seen relating to this error seem to be hyper-focused on solving a specific instance of this error. So - What is this error trying to tell me is wrong?
More context. I attempt to execute the PyMultinest (PMN) package as directed in the PMN documentation. PMN is, effectively, a Python wrapper for a C program. Running PMN requires a fair bit of setup code (several ancillary functions need to be defined, as well as a host of variables), which I'm not including here by default because it's ... a lot, but I can if needed. The PMN execution line I use is
pmn.run(Loglike, Prior, ndims, n_live_points=1000, n_params=n_params, outputfiles_basename='./'+ProjectName+'/temp_', resume=False, verbose=True)
This returns the error traceback
File "[redacted]", line 139, in <module>
pmn.run(Loglike, Prior, ndims, n_live_points=1000, n_params=n_params, outputfiles_basename='./'+ProjectName+'/temp_', resume=False, verbose=True)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymultinest/run.py", line 254, in run
lib.run(*args_converted)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 386, in __getattr__
func = self.__getitem__(name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 386, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, run): symbol not found
If it helps, I have determined that the name variable being passeed through self.__getitem__(), and thus into self._FuncPtr(), is run. Although, that might be obvious looking at the AttributeError message.
I am running Python 3.8 (as shown above) on a MacOS machine. Last summer, I was able to execute PMN on this machine using extremely similar code to that which I am using now. I am currently trying to optimize my code from last summer, which is why I'm surprised it isn't simply "working".
So far my attempts at fixing this have been mostly centered on reinstalling PMN. I have done a clean install (pip uninstall/pip install) of the PMN package, as well as following the PMN documentation to rebuild the C portion of the package. I have included the source directories of the C software in my Path variables - or at least, I tried to, I am assuming I was successful, but I'm not very familiar with Macs.
Ultimately, I just wish I understood what Python was telling me with this error better. It would help me direct my own attempts at solving the issue. I suspect it is saying "We don't know where to find this 'run' command you're asking for," in which case I need to figure out why my Path variable changes aren't working. Am I on the right path?
Some hints how to resolve this are given in these issues:
https://github.com/JohannesBuchner/PyMultiNest/issues/160
https://github.com/JohannesBuchner/PyMultiNest/issues/163
It is important to cleanly recompile (empty build folder) when the environment changes, so that cmake recognises changed libraries and compilers.
Check if you are running everything with python3 and not python (works as python 2.x is you have both version 2 and 3 installed)
Check is all the PyMultiNest python files are rewritten in python 3 style, e.g. $ print "something" becomes $ print("something")
My supervisor was accidentally running on python 2.7 and got the same error, so your error might as well be due to mismatch of python version usages.
Run command flutter pub cache clean and flutter clean and after that run flutter pub get now relaunch your emulator it worked for me.

Tensorflow is working in python shell but not in python file

I'm new to Tensorflow. I installed it using pip install. The thing is when I enter this code in python shell, it works
import tensorflow as tf
print(tf.__version__)
but when I enter the same code in Idle, it imports the tensorflow module but gives error in the next line that
AttributeError: module 'tensorflow' has no attribute '__version__'
what could be possibly the reason?
Ok so I made a stupid mistake, I named the file that I was creating as tensorflow.py, which obviously was conflicting with actual tensorflow file. This was causing the bug. Comment from #Mitiku made my realize my mistake.

AttributeError in PyCharm

Very simply, I cannot get .format to work in my code. For Example, when I write:
print("abc{0}def".format("x"))
I end up with the following error:
print("abc{0}def".format("x"))
AttributeError: 'str' object has no attribute 'format'
I am just beginning to learn Python and I am getting this error in PyCharm Community Edition 5.0.3
It is interfering with my assignments and my professor has no idea what the issue is.
By switching my Python Interpreter in settings I was able to switch PyCharm from version 2 to version 3, which solved all of the issues.

Categories