Code error- Python 2.7 - python-2.7

I pip install requests module and bs4 module. In C drive i can see the installed modules:
and this is the sys.path of the added modules:
When i check all sys.path with:
import sys
for i in sys.path:
print i
UPTADE
i get this list:
C:\Python27new\Lib\site-packages
C:\Program Files (x86)\ArcGIS\Desktop10.3\bin
C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy
C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcToolBox\Scripts
But when i try to import requests and bs4 modules i get an error:
>>> import requests
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import requests
ImportError: No module named requests
and the same for bs4 module:
ImportError: No module named bs4

If the picture is a listing of C:\Python27new\Lib\site-packages then you want that in your path, not C:\Python27new\Lib\site-packages\requests.

Related

Python 2.7 Import libsoundtouch

I want install libsoundtouch ("pip install libsoundtouch"). after install process, everything seems correct, but when I run my script python(2.7) can import this module.
After check I have files in "/usr/local/lib/python2.7/dist-packages/libsoundtouch".
#!/usr/bin/python
# -*- coding: utf-8 -*-
import libsoundtouch
./home/pi/myprog/scripts/python/test.py
Traceback (most recent call last):
File "./home/pi/myprog/scripts/python/test.py", line 5, in
import libsoundtouch
File "/usr/local/lib/python2.7/dist-packages/libsoundtouch/init.py", line 9, in
from zeroconf import Zeroconf, ServiceBrowser
File "/usr/local/lib/python2.7/dist-packages/zeroconf.py", line 189
def current_time_millis() -> float:
^
SyntaxError: invalid syntax

error 'import string_types ValueError: Attempted relative import in non-package'

Using cmd on windows 10 to run Python 2.7.16. When I run a .py file which imports scipy.py it comes up with the error:
"File "C:\Python27\scipy.py", line 18, in
from .python import string_types
ValueError: Attempted relative import in non-package"
As string_types should already be included in python, I don't understand why this error is happening and cant seem to get passed it. Does anyone know how to fix this?
you tried,
>>> from . import MyModule #MyModule.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Attempted relative import in non-package
>>>
here . mean your current path
try,
from MyModule import *
now you can use string_types
or
import MyModule as m
m.string_types

Python Scipy.stats operations do not work when copied to another machine (where there is no python installed) with the source folder

I am using Scipy.stats to perform distribution fits on my data. It works perfectly on my machine. But when I package my script with Python source folder, python27.dll and try to run it on another machine (where python is not installed and I do not want to also) by invoking my script like below
Path/to/Python.exe Path/to/script.py
I get the follwing error
Traceback (most recent call last):
File "test2.py", line 2, in <module>
import scipy.stats
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\stats\__init__.py
", line 344, in <module>
from .stats import *
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\stats\stats.py",
line 173, in <module>
import scipy.special as special
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\special\__init__.
py", line 636, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
My script is
import sys
import scipy.stats
import numpy
dataarray= [2.45, 3.67, 1.90, 2.56, 1.78, 2.67]
desc = scipy.stats.describe(dataarray)
print desc
This occurs only on Scipy import and scipy operations, all other imports and operations work fine. My purpose is to run this script in different machines without having to actually install python

ImportError: No module named if trying to execute from command line

I am getting following error
D:\pythongui>C:\Python27\python.exe D:/pythongui/controller/MainController.py
Traceback (most recent call last):
File "D:/pythongui/controller/MainController.py", line 5, in <module>
from view.MainView import Launcher
ImportError: No module named view.MainView
when I am executing the following command in terminal
C:\Python27\python.exe D:/pythongui/controller/MainController.py
But the same code is working in pycharm without any error.
My Directory structure is as follows :
I have tried following code
import GetMyIp as getMyIP
import sys
sys.path.append("view/MainView")
import Server as server
import view.MainView

Python Module Import from another directory

I'm getting a module import error.
My main file is /home/mininet/pythonscripts/import.py:
and my module file is /home/mininet/test/hello.py:
The error I'm getting is:
File "import.py", line 7, in <module> from test.hello import sqr,print_func
ImportError: No module named hello
i also added the __init__.py file in the module search path..please help!!
In order to import /home/mininet/test/hello.py as test.hello, you have to fulfill two requirements:
/home/mininet/test/__init__.py must exist to mark test as a package.
/home/mininet must be on sys.path so that Python finds test/hello.py when looking for test.hello.
Note that having /home/mininet/test on sys.path lets you import hello, but not import test.hello.