twisted installed on mac os x but not importing - python

When I try to use twisted from python it fails to load. Extras path is not in my sys.path. Even when I add it to sys.path it fails to load twisted. Any ideas?
sudo find / -name twisted
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/twisted
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from twisted.internet.protocol import Factory
Traceback (most recent call last):
File "test.py", line 1, in <module>
from twisted.internet.protocol import Factory
ImportError: No module named twisted.internet.protocol

Have you made sure that all permissions are set properly? If you installed it by hand it might be a problem with the permissions. Check that the permissions are 644 for files and 755 for directories.

Related

Cannot use socket

I am trying to import socket and I get the following error:
$ python
Python 2.7.16 |Anaconda, Inc.| (default, Mar 14 2019, 16:24:02)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "socket.py", line 68, in <module>
from _ssl import \
ImportError: cannot import name RAND_egd
I thought that perhaps my Anaconda installation was corrupted so I uninstalled and reinstalled Anaconda but the error persists.
I had tried what the other posts suggested except for editing socket.py due to Macos System Integrity Protection. My guess is that the problem lies elsewhere as I doubt that everyone has had to edit the file.
How can I find the source of the problem?

Python failing in sub directory, but working in home directory

I have an Ubuntu machine (18.04) on a VM. When I run python in the home directory, everthing responds normally, however when I run from a sub directory it is failing to import modules in the standard library.
The sequence below illustrates the problem
anon#anon-VirtualBox:~$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>import os
>>> os.environ['PATH']
'/bin:/home/anon/anaconda2/bin:/home/anon/bin:/home/anon/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'
>>> import logging
>>> exit()
Which is the expected behaviour.
However when I go into a subdirectory, the same operation fails
anon#anon-VirtualBox:~$ cd GitHub/bikeano
anon#anon-VirtualBox:~/GitHub/bikeano$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['PATH']
'/bin:/home/anon/anaconda2/bin:/home/anon/bin:/home/anon/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'
>>> import logging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "logging.py", line 5, in <module>
import logging.handlers
ImportError: No module named handlers
>>>
I do not understand what is happening here. Are there other environment variables which could affect this?
Also, this is occuring on a Virtualbox VM, and the same .vdi works normally on another machine? The host is Windows 10 on both machines.

Why do I get a ModuleNotFoundError for winreg on a Linux system?

'winreg' module is not found python 3.6.7. I am not facing this problem in Python 3.4.
Is any third-party app in 'winreg' that I can use same code or how can I solve this.
jaki#jaki-notebook:~$ python3 -V
Python 3.6.7
jaki#jaki-notebook:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from winreg import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'winreg'
>>>
ModuleNotFoundError: No module named 'winreg'
It is not work on linux because this package expose functions of the Windows registry API to Python
Read this documentation on python offical website

python ModuleNotFoundError: import works from console but not from nested modules

I have a module called _local at the root of my project, and a file in another module that imports it:
when I run python _devtools/test_import.py from root folder, I get an error:
python _devtools/test_import.py
Traceback (most recent call last):
File "_devtools/test_import.py", line 1, in <module>
import _local
ModuleNotFoundError: No module named '_local'
when I try to import this module from the console, while staying in the same root folder, it works:
python
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _local
>>>
What should I modify in my environment variables to make the import work?
The _local module is not visible from _devtools and cannot be accessed using relative imports since you are running the temp_import.py as the main script.
Here is simple hack using the sys.path modification,
import sys
sys.path.insert(0, "../_local")
import _local

Python3 can not find module xmlrpc from unittests

I am working on a python project with 2 other people, but I can't run our tests. When I run the tests using python3 -m unittest I get this output
Traceback (most recent call last):
Traceback (most recent call last):
File "Peer.py", line 1, in <module>
File "Peer.py", line 1, in <module>
from xmlrpc.client import ServerProxy
from xmlrpc.client import ServerProxy
ImportError: No module named xmlrpc.client
ImportError: No module named xmlrpc.client
Line 1 in Peer.py is
from xmlrpc.client import ServerProxy
The strange thing is that when I run Peer.py independently (python3 Peer.py) there are no problems. And it also works like a charm in the shell
Python 3.3.1 (v3.3.1:d9893d13c628, Apr 6 2013, 11:07:11)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xmlrpc.client
>>>
The 2 people I work with don't have any problems, and we are running the same code from version control. I get the same error on both OS X and Ubuntu, whereas they run Windows.

Categories

Resources