AttributeError in PyCharm - python

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.

Related

Error occurred after updating and changing PYTHONHOME variable

After changing some environmental variable for PYTHONHOME and updating pycharm and python my console kept spitting out this error:
def __new__(mcls, name, bases, namespace, /, **kwargs)
^
SyntaxError: invalid syntax
I've search through some similar problems and tried to reinstall python and let it set the path but the problem still occurred.
For reference my first error that lead to this was akin to what happened int his question: Fatal Python error on Windows 10 ModuleNotFoundError: No module named 'encodings'.
Then i tried the solution in this question: Fatal Python error: init_sys_streams: can't initialize sys standard streams AttributeError: module 'io' has no attribute 'OpenWrapper'
And now i found myself with the above error of which am at a standstill. Ive tried looking for the syntax one would use for this new and perhaps found the error in there but so far no good.
Edit 1: Removed a / from _py_abc.py and it now says ImportError: cannot import name 'open_code'
I've got the same error after I've installed and tried to use python 3.8 in eclipse.
The exact line of code is inside the _py_abc.py module/file, and it contains a feature that was introduced in python3.8, the positional only parameters.
In my case, the error was raised while pylint (which was installed with pip2/python2) was trying to ... lint, and persisted even after I've installed pylint with pip3/python3 (which in my Ubuntu 18.04 WSL points to python3.6). I've managed to overcome the problem only after I've installed pylint explicitly with python3.8.
So, this whole ranting about pylint is only to explain how I got the error and how I understood the problem which basically is: some thing inside the IDE is trying to use some pre-3.8 executable to run something that should be run with a python3.8+ executable.

Shakespeare Programming Language Help - Windows

I've recently gotten interested in the esoteric programming language Shakespeare Programming Language (SPL) and have tried to install the only windows-friendly interpreter I could find, from:
https://pypi.python.org/pypi/shakespearelang/0.2.0
It was my first time installing pip and python (3.6) as a whole, although I believe I have installed everything correctly.
When I try to interpret a legitimate SPL file with:
shakespeare run helloworld.py
I get the error:
File "c:\...\shakespearelang\shakespeare_interpreter.py", line 151, in run_event
self._character_by_name(name).on_stage = True
AttributeError: 'NoneType' object has no attribute 'on_stage'
Everything else in the interpreter seems to work properly except calling the someone to "the stage".
Any fix to this error or an alternative windows-friendly compiler/interpreter would be great.
You asked:
Any fix to this error or an alternative windows-friendly
compiler/interpreter would be great.
Here is an alternative you could try. It is a web-based "IDE" for building and running SPL programs.
I believe that the file should be helloworld.spl instead.

Truncated SVD attribute 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.

StochPy missing module when using PyDev in Eclipse

I use PyDev in Eclipse for Python coding. I need to use the Stochpy package. I already have it installed and it works fine in the Command Prompt. However, it gives me "AttributeError: 'module' object has no attribute 'SSA'" error when running in Eclipse.
Why is that?
The code is as simple as:
import stochpy
smod = stochpy.SSA()
The second line gives me error:
AttributeError: 'module' object has no attribute 'SSA'
Thanks!

error while using FREAK

I'm trying to create Descriptor extractor using FREAK. but
at the following line:
freakExtractor = cv2.DescriptorExtractor_create('FREAK')
I get an error saying:
freakExtractor = cv2.DescriptorExtractor_create('FREAK')
AttributeError: 'module' object has no attribute 'DescriptorExtractor_create'
can someone tell me what is the exact problem and why i'm getting this error?
I'm using ubuntu 12.10 with opencv 2.4.3 and python 2.7.
I think,
cv2.DescriptorExtractor_create('FREAK')
is not a part of python interface, just use the latest opencv for that then it will work or you simply can write the code in c++ which is availabe in that version in c++.

Categories