Python not Cooperating - python

I am creating a joint project using both Python and R in Visual Studio. I imported Tkinter from Python to create the interface and using R via rpy2 for analyzing data. I am stuck with this error code:
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Traceback (most recent call last):
File "C:\Users\15309\OneDrive\Desktop\Python\Lib\io.py", line 54, in <module>
ImportError: cannot import name 'open_code' from 'io' (unknown location)
I am using Python 3.7 in Visual Studio and rpy2 is imported from Anaconda's Python 3.7. My instructor and I have not been able to figure out how to fix it. What do we need to do?

I guess your filename is io.py
Change its name to something else.

Related

Python "import random" generate "ImportError: cannot import name 'MethodType'"

I am using
Visual Studio 2017
Python 3.6 64 bit
When I use the Visual Studio built interactive environment, I am about to "import random" no problems
When I run the code (without the debugger) I get the following error
Traceback (most recent call last):
File "C:\Users\Andy Slater\github\Introduction to Python Fundamentals\Introduction to Python Fundamentals\sorting.py", line 149, in <module>
import random
File "C:\Program Files\Python36\lib\random.py", line 41, in <module>
from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType
ImportError: cannot import name 'MethodType'
I'm no pro, but I think you're having a dependency problem. Have you messed around in the python directory at all? Random comes with the standard library, and so does types. You can try un-installing and re-installing python, or updating it. You might also try to see if you can just pip install 'types'

How do i ensure i can import pythoncom and pywintypes so i can build a COM server in python 3.4?

Im a trying to build a COM server in Python. I have downloaded and installed Pywin32 (I use 32-bit version of Python 3.4.1, so I downloaded and installed pywin32 for this version).
Now, in order to import pythoncom in IDLE, I need to have two .dll files readily accessible:
-pythoncom.dll
-pywintypes.dll
Both .dll files are in the following directory:
C:\Python34\Lib\site-packages\pywin32_system32
When I give the import statement in IDLE, I get the following error:
Traceback (most recent call last):
File "", line 1, in
import pythoncom
File "C:\Python34\lib\site-packages\pythoncom.py", line 2, in
import pywintypes
ImportError: No module named 'pywintypes'
I reinstalled pywin32, but it still doesn't fix it.
I am now trying to add C:\Python34\Lib\site-packages\pywin32_system32 to my PATH directory, but it doesn’t work. I am trying this via:
os.environ["PATH"] += os.pathsep + C:\Python34\Lib\site-packages\pywin32_system32
I then get the following message:
The syntax of the command is incorrect.
What error am I making in the syntax above? How can I fix this (i.e. how can I add C:\Python34\lib\site-packages\pythoncom.py to my PATH environment)?

Python ImportError NetCDF4

I've been using Python to treat some data that is in netcdf format... Usually I type the code within Pycharm a Python IDE, which I've configure to run the Python scripts with the system install.
To read the .nc files I use the NetCDF4 package and I've no problem when running within Pycharm. However, when I try to run the same script but from the system command line I always got the following error:
Traceback (most recent call last):
File "CheckDate.py", line 2, in <module>
import netCDF4 as n4
ImportError: /usr/local/lib/python2.7/dist-packages/netCDF4.so: undefined symbol: nc_inq_var_endian
Can anybody give me some help to fix this?

Python - cannot import slycot module in spyder (RuntimeError & ImportError)

When I try to import the slycot module in spyder (version 2.2), I get the following error:
RuntimeError: module compiled against API version 7 but this version of numpy is 6
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/slycot/__init__.py",
line 4, in <module>
from slycot.analysis import ab01nd,ab05md,ab05nd,ab07nd,ab08nd, ab09ad
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/slycot/analysis.py",
line 21, in <module>
from slycot import _wrapper
ImportError: numpy.core.multiarray failed to import
Now, when I import slycot in the python shell through my terminal, there are no problems at all. I think the reason why there are no problems through the terminal, is that I recently installed numpy 1.7.1. Spyder on the other hand still uses numpy 1.6.2.,hence the error.
I tried to change the numpy version in spyder, but so far that didn't work.
When I change the numpy(6) folder in my spyder lib with the recently installed numpy(7), I get the following error (in spyder):
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
What is the best way to solve this error?
Thanks in advance.
(Spyder dev here) At the moment it's not possible for the user to install anything inside the app. I guess you moved your slycot module from another interpreter to our App (because of the numpy error you mention).
The right way to use different modules not present in the app, is to change the path of your interpreter in:
Tools > Preferences > Console > Advanced settings > Python executable
If you installed slycot using your system Python, you have to select
/usr/bin/python

win32com DLL load failed

I'm trying to add win32com to Python 2.7. After looking at this, I added the directory with the _init file (Python27\Lib\site-packages\win32com) but I still get it. I went so far as to try to add a bunch of different folders to the path that seem to have to deal with win32com but I still get the error. If it knows where the file is and I added that folder to PYTHONPATH, why is this happening? I'm using PyDev with Eclipse Juno. My code:
import win32com.client
print("hello world")
when I try to run this, i get this error
Traceback (most recent call last):
File "C:\Users\Daniel\EclipseWorkspace\PhotoScript\src\scriptLaunch.py", line 1, in <module>
import win32com.client
File "C:\Python27\Lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: The specified module could not be found.
in my case typing in cmd:
python C:\Python27\Scripts\pywin32_postinstall.py -install
cmd Windows
I hope this helps
Try installing ActivePython, it includes win32com:
The Python for Windows Extensions (PyWin32 version 214).
The interface to the Win32 API (win32api).
The interfaces to Win32 COM (win32com and win32comext).
The Pythonwin Development Environment.
*ActivePython is fully binary compatible with python.org Python builds to ensure that 3rd-party binary extensions just work*
Try to install python for windows extensions:
https://sourceforge.net/projects/pywin32/files/pywin32/Build%20210/

Categories

Resources