I'm trying to open an Excel file using Pycharm, but always get a the following message:
Traceback (most recent call last):
File "C:/Users/.../PycharmProjects/Excelmodules/openxlsx.py", line 2, in <module>
from openpyxl import openpyxl
ImportError: cannot import name 'openpyxl' from 'openpyxl' (C:\Users\...\PycharmProjects\Excelmodules\venv\lib\site-packages\openpyxl\__init__.py)`
Process finished with exit code 1
I have successfully installed Openpyxl in Pycharm (using another thread on stackoverflow) and have checked the file name/path is correct, but still get the error message.
I am new to python so it might be something I have/haven't done, but the only things I can think are causing this are:
running it through Pycharm rather than command prompt
Windows 10 did a forced update and created an "old windows folder and I'm wondering whether Pycharm or openpyxl are trying use/run using the old.windows folder
the Excel file needs to be in the Pycharm folder
I was starting a project in Automate the Boring stuff, but can't get past this step.
Please help!
Thank you
Rob
Related
Henlo everyone,
I met a very specific problem with my Python installation. I have a PyCharm project using a venv with pywikibot installed. Whenever I try to import the module, I get the following error:
Traceback (most recent call last):
File "C:/Users/<username>/<path to project>/alphabets/coptic_characters.py", line 1, in <module>
import pywikibot as pwb
File "C:\Users\<username>\<path to project>\venv\lib\site-packages\pywikibot\__init__.py", line 15, in <module>
from decimal import Decimal
File "C:\Users\<username>\Anaconda3\lib\decimal.py", line 3, in <module>
from _decimal import *
AttributeError: module 'numbers' has no attribute 'Number'
It appears to have broken itself because earlier in the day it worked with no problems.
I also have the module installed on a global Anaconda3 setup elsewhere in my computer. It works fine everywhere except, that's where it gets weird, when I try to execute it inside the project directory. It gets even stranger than that, if I execute the interpreter in a sub-folder, it works again. I don't understand what's happening here at all…
I tried creating a new project but I get the same error and behavior.
What am I missing? I don't understand why it stopped working suddenly event though I did nothing to the venv.
P.S.: I'm on Windows 10.
So !
It appears that a module I created with the name numbers was interfering with Python's code. I just changed the name and it suddenly worked again !
Thanks to #furas for suggesting this.
Pretty new to all this so I apologize if I butcher my explanation. I am using python scripts on a server at work to pull data from our Oracle database. Problem is whenever I execute the script I get this error:
Traceback (most recent call last):
File "update_52w_forecast_from_oracle.py", line 3, in
import cx_Oracle
ImportError: libnnz11.so: cannot open shared object file: No such file or direct ory
But if I use:
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
Before executing the script it runs fine but only for that session. If I log back in again I have to re-set the path. Anything I can do to make this permanent? I'm trying to use Cron as well to automate the script once a week. It was suppose to automate early Monday morning but it didn't run.
EDIT: Just had to add the path to my .bashrc file in the root directory.
Well, that was pretty simple. I just had to add it to the .bashrc file in my root directory.
I am writing a code which I want to have details to its own directory. e.g. C:\Users\User\Desktop\helloworld.py
Is there a way to find it from within the program using pywin32 or any other module?
If so, once I turn it into .exe using py2exe will it still be able to find it's own directory(C:\Users\User\Desktop\dist\helloworld.exe)
I tried the following code:
print os.path.dirname(os.path.realpath(sys.argv[0]))
This works but once I turn it into a .exe file it doesn't manage to run.... What other solutions can there be?
The error I get in the log file is the following error:
Traceback (most recent call last): File "finddirectory.py", line 4, in EOFError: EOF when reading a line
You can find that information on the py2exe wiki:
http://www.py2exe.org/index.cgi/WhereAmI
I have an issue with running python scripts on one server running RH Linux with Python 2.6.6. When I run any script and it produces an exception, the script hangs until I press CTRL-C and then it prints the traceback information. It happens when I run the script from the command-line without calling python directly, making use of the shebang on the first line of the script. If I execute the script by calling python , I don't have the same hanging issue. I've searched and seen similar issues, but they were related to specific libraries where this happens with all python scripts. I've tried a different servers with the same script and didn't have the issue. I have included a simple script that I have been testing with. It tries to open a non-existent file.
#!/usr/bin/env python
tempfile = open('noexists.txt','r')
When I execute the code as "test.py" on the command-line, I get the following response:
~/bin$> test.py
^CTraceback (most recent call last):
File "/export/home/jwd3/bin/test.py", line 2, in <module>
tempfile = open('noexists.txt','r')
IOError: [Errno 2] No such file or directory: 'noexists.txt'
If I execute it as "python test.py" then I get the following response:
~/bin$> python test.py
Traceback (most recent call last):
File "test.py", line 2, in <module>
tempfile = open('noexists.txt','r')
IOError: [Errno 2] No such file or directory: 'noexists.txt'
The difference is difficult to tell here, but it is very evident when executing. Look at the first sample output and notice the "^C" before the Traceback. Until I hit CTRL-C, the script was just hanging. The second sample output returns the traceback of the exception imediately without hanging.
I've tried moving the script to a new location, changing the shebang from #!/usr/bin/python to #!/usr/bin/env python and different scripts. In all cases they behave the same. Any help would be greatly appreciated. I do not want to call all python scripts using "python " format.
Thanks to the help from the suggestions above, I was able to find the solution to the issue. After running strace, I found the code was hanging on a socket connection. Searching for the same socket connection info, I found another issue already posted on Stack Overflow that was similar. I then found a second issue that was also very similar. Both issues had the same suggestion. Apparently the Python script was conflicting with a service called abrtd. The suggestion was to restart this service (abrtd). After restarting it, the issue with the Python script hanging was resolved.
Okay I am newer to python and have been researching this problem but I can't find anything like it so I am not sure what is going on.
I am creating a program that involves sage and it has a message cue. We have this set up on a development machine, so I know it works but I was wanting to set it up on my own computer so I could get a better understanding of how it all works and make it easier to develop for myself.
To start up sage, we run a script that calls sages main binary file and passes it an executable .py file. (./sage/sage ./sage_server.py) This creates an error in the sage_server.py file:
Traceback (most recent call last):
File "./sage_server.py", line 23, in <module>
from carrot.messaging import Publisher
ImportError: No module named carrot.messaging
But whenever I run that file just in the terminal (./sage_server) the import works fine and isn't until line 27 that there is an error when it tries to import something from sage.
Does anyone know what would cause the error when it is being called by something else? I am very lost as to what would be causing this.
Sage has its own python, separate from the system libraries. This "carrot" module, whatever it is, must be installed in whatever python ./sage_server.py uses, but not in Sage.
You should be able to use either
[your-sage] -sh
to start up a Sage shell and use easy_install, or you could get whatever carroty package you're using, find its setup.py file, and then run
[your-sage] -python setup.py install
where obviously your-sage is the path to your sage.
Things get a little trickier if the install process isn't setup.py-based.