ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I works when I type the stuff in konsole, but when runnning the script it gives the error
$ python math.py
Traceback (most recent call last):
File "math.py", line 3, in ?
import math
File "/home/christoffer/python/math.py", line 5, in ?
decibel = math.log10 (17.0)
AttributeError: 'module' object has no attribute 'log10'
I have tried switching "#!/usr/bin/env python" with "#!/usr/bin/python python" because "which python" gives "/usr/bin/python" but I don't work either.
Do you have a file in the current directory called math.py?
When you run your python script it is importing the math.py from your current directory which does not have the log10 attribute.
try copying your test file to /tmp and running it from there, do you get the same problem?
The file is in /home/christoffer/python/math.py
and run standing in that directory.
Copying to tmp and runing from there don't help.
How can I make it point to math, so it uses it?
(1) it should just be "#!/usr/bin/python", not "#!/usr/bin/python python".
(2) the file tries to import itself--python resolves imports by looking in the current directory first. You can either import the math library using the same functions some deep, low-level code uses, or just rename your file.
Originally posted by jonaskoelker
(1) it should just be "#!/usr/bin/python", not "#!/usr/bin/python python".
The posted script has "#!/usr/bin/env python", not "#!/usr/bin/python python".
"#!/usr/bin/env python" is correct, and often used for python scripts. I don't understand however the difference between "#!/usr/bin/env python" and "#!/usr/bin/python"
I have tried switching "#!/usr/bin/env python" with "#!/usr/bin/python python"
That's what I was referring to. But nevermind. "If it ain't fixed don't break it".
The difference is that with the absolute path (#!/usr/bin/python), if the python executable is stored anywhere else (say, /usr/local/bin/python), your script won't run. By using env, you fix the location of env instead of python; I think env is more often found in /usr/bin that python, so that's why.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.