I'm new to python and I'm using jython to create classes from python files.
I have jython and python both configured in my environment variables and when I type either in the command prompt I get their respective versions.
That's right I'm using windows :(
I need to create json output and was able to finally get the 'import json' to work and not give me an ImportError: No module name json.
Now I would like to import pysftp but I'm getting ImportError: No module named pysftp. Same thing with Paramiko import.
With that said I updated my jython to 2.7 and python version to 2.7.9 so I can use pip to import those libraries. Is this really what pip is for? How do I import library pysftp into my py file without it giving me the ImportError?
I'm a Java guy so I tried to locate pysftp jar and add it to the python Lib folder but that didn't work.
How do I import python libraries?
Related
A Python script starts with:
from pathlib import Path
import sqlite3
which I read as an initialization of Libraries needed to run the rest of the script. However if the following error is returned in the terminal:
ImportError: No module named pathlib
I am uncertain how to interpret this. One assumption is that the pathlib library is uninstalled. However on the local system Python 2.7 and Python 3.4 are installed (I believe one was system pre-installed).
How can a library be asserted to exist? In case it is missing, how can it be installed?
You have to install it first
pip install pathlib
And with that your code should work.
I want to import the paramiko module located in /usr/local/lib/python2.7/dist-packages. So, I imported it this way:
from usr.local.lib.python2.7.dist-packages import paramiko
I have an error syntax related to python2.7 (It considers 7 as a package located in python2 package)
I have both Python3.1.3 and Python2.7 installed. I program with Python3.1.3 only, however.
How can I resolve this problem ?
How about ?
import sys
sys.path.append('/usr/local/lib/python2.7/dist-packages')
import paramiko
UPDATED
The best solution is installing paramiko on Python3 env. Take a look at #DanielRoseman's answer. Or virtualenv is worth consideration. Here is a good tutorial. http://simononsoftware.com/virtualenv-tutorial/
I don't know why you think you need to include the full path. That directory will already be included in the Python path. You just need to do import paramiko.
Edit after comment Well you can't randomly import things that are installed for a different version. There are several backwards incompatibilities, and anything that has any compiled extensions will just not work at all.
You need to download and install paramiko for your 3.1 installation, rather than trying to use the 2.7 version. python3 pip install paramiko, as an example.
(Also, you shouldn't really be using 3.1. If you're using the Python 3 series you should upgrade to 3.4.)
I have a program here that I would like to convert to 2.7. This code works well in Python 3.x, however, for my needs it must be 2.7. Could someone 'convert' this to python 2.7 for me? I have heard of a 3to2.py tool but I do know how to get/use it. Anyway, here is the code I have for 3.3.
def compiler(program):
import os, win32com.client, time
os.startfile("C:\\Windows\\System32\\cmd.exe")
time.sleep(2)
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate('C:\\Windows\\System32\\cmd.exe')
setup(program)
shell.SendKeys("py MyCompiling.py.setup("+program+") py2exe\n")
def setup(program):
from distutils.core import setup
import py2exe
setup(console=[program + ".py"])
compiler('test1')
EDIT: When I try to run I get
ImportError: No module named win32com.client
Do I have to install this module seperately? If so, could someone please post the link.
Yes, you must install the library separately. In fact, if you visit the SourceForge page, you will see that there is an entirely different binary available for 2.7. You will want pywin32-218.win32-py2.7.exe if you are using 32-bit Python or pywin32-218.win-amd64-py2.7.exe if you are using 64-bit Python.
You can install it via the GUI interface (which comes up when you try to execute the file), or you can call easy_install on it (if you have setuptools or distribute installed) at the command line:
C:\> C:\Python27\Scripts\easy_install pywin32-218.win32-py2.7.exe
Using easy_install is the only way if you want to install the library in a virtual environment created with virutalenv.
My server has python older version(2.6~), so I have created a separate dir for installing latest python. I have installed from binary .
Now, got error that 'bz2 module is not available'
got this problem when installing django-celery.
it is actually working from system level python like this:
/usr/bin/python:
python shell opens......
then, import bz2; works !!!
python (means, locally installed python, after source /venv/bin/activate)
in python shell, import bz2; says that it is not available. Can you please make it work for my local version( not global one).
Resources I found and tried from :
ImportError: No module named bz2 for Python 2.7.2
Python's bz2 module not compiled by default
A very similar question describes the same problem but for zlib. In short, you'll need libbz2.so and its headers in some location where Python can find them. You might need to download the bzip2 source code and compile/install that in your homedir as well.
I am on Mac 10.6.8 with MAMP server installed.
I have installed both Scrapy and MySQLdb module under Python 2.6
When i import MySQLdb module from a python command line or in another project i see no error and it's working as expected. However when i import MySQLdb module in Scrapy project i get import error ("ImportError: No module named MySQLdb").
I am not a Python guru and such behavior is quite unexpected.
Why is that happening ? How this can be fixed ?
$ which python
/opt/local/bin/python (which is a symlink to "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6")
$ which scrapy
/usr/local/bin/scrapy
You have multiple Python instances installed (e.g., one is OS X built-in, another from MAMP). Check that those modules are actually installed in MAMP Python 2.6 (see what site-packages directory they reside in).
If you installed a module using easy_install from the built-in Python, you would not be able to use it from other Python instances.
P.S. Why use MAMP at all? Mac OS X already has all the components you need (Apache, MySQL, Python).