Import library zip in Python - python

I am looking at an older version of python code
from itertools import izip
but when I run it, it says
ImportError: cannot import name 'izip'
Anyone know how should I import?

In Python 3+ you just use zip instead. It's builtin, so you don't have to import it. Try using the 2to3 tool to update the code automatically.

Related

import from lib in python

I import vtt_to_srt converter.I read the instructions.I make the installation.From beginning to this "no problem" but when I import it as manuals describe python can't find the module there.
Installation
pip install vtt_to_srt3
Usage
from vtt_to_srt import vtt_to_srt
path = '/path/to/file.vtt'
vtt_to_srt(path)
Error
ImportError: cannot import name 'vtt_to_srt' from 'vtt_to_srt'
I am a rookie.Sorry for asking this question.
#SakuraFreak's answer was my immediate thought, too, but I ended up investigating this a bit further. It seems like vtt_to_srt stores all its API in the __main__.py file of the module. This file should normally be used when you want to a module using python -m.
This actually makes the module impossible to use the way that the documentation specifies. What I tried, then was:
from vtt_to_srt.__main__ import vtt_to_srt
print(vtt_to_srt)
This results in:
<function vtt_to_srt at 0x000002A0948216A8>
So it seems like this workaround is OK.
I do not know if storing all the module's code in __main__.py is some convention not supported by my version of Python (CPython 3.7.3 on Windows), or if it simply an error. Maybe you should approach the module's owners with this.
Because you're trying to import a function from the module which doesn't exist.
the correct way for this module is:
import vtt_to_srt

How to install project in git repository correctly in python?

Im newbie in python and know i a task from my lecturer to use ANFIS. so I intall anfis in my virtual environent using
pip install anfis
and now I try to import that
import anfis
import membership #import membershipfunction, mfDerivs
import numpy
i got problem
ModuleNotFoundError: No module named 'membership'
so what I must do?
Looks like membership is part of the anfis package, but you are trying to import it as if it were an independent package in itself. Since you haven't installed any package called membership (probably because it doesn't exist as a package), you are getting a ModuleError.
Solution:
First of all, remove the following statement from your code, which is causing the error message:
import membership
Next, since you are already importing the entire anfis package, you can just use a function from the membership module in your code like this:
import anfis
# some code
mfc = membership.membershipfunction.MemFuncs(mf)
Check this link from the anfis GitHub repo for an example on how to use the membership function.
This seems to be a common problem. Try reading through this discussion and see if anything there helps you.
https://github.com/twmeggs/anfis/issues/4

Can I import a library in zapier code

Is there a way to import a library in Zapier Python Code?
Specifically, I want the 'datasift' library.
When I try, I just get "ImportError: No module named datasift"
In the zapier documentation, it specifically says that it only allows for the requests import and standard python imports
We can import only requests, so we need to find another way to run any python code which include the other libraries.
Maybe, we can build python to exe file and run it directly by zapier service.

Importing Python script with nonstandard name

I am writing a series of python scripts to extend the QGIS software suite. As such I am trying to follow their naming conventions. In this instance the file I am trying to import is called "r.sun.distributed". Ive tried using import r.sun.distributed and import("r.sun.distributed") However, python says it can't find a module by that name in both cases.
Is there a work around, or do I need to rename my scripts so they fit Python's conventions?
You can use the imp module to import modules without .py extension:
import imp
imp.load_source(path)
you have to convert it to .pyc to call it.
import py_compile
py_compile.compile('filename.py')

How do i convert my Python script (that has imported modules) to a windows exe?

Here are the import modules that my script uses :
import datetime
from dateutil import parser
from tkinter import filedialog
import tkinter
import mailbox
import pprint
import json
import urllib.request
from tkinter import *
#my script code here
How can i convert it into a windows exe. Im using python 3.4. People have suggested cx_freeze however there is no documentation on it therefore have no idea how to use it? Py2exe worked on a test script with no imported modules, but when i tried to compile my script, it didnt work? If my script is called test.py, what would the cx_freeze command be to covnert it?
Try www.py2exe.org/
py2exe is a nice module that you may find useful.
Or, if you are in linux/mac then you might try freeze method try https://wiki.python.org/moin/Freeze
I highly suggest PyInstaller.
I used to use it in order to create the exe file with multiple library files, then compress all these files into a self extracting archive, obtaining a fully working standalone exe file.
It doesn't require other scripts or code, you only have to create the file using "Makespec.py" and "Build.py".
If I'm not wrong, there is a new version compatible with Python 3.4...otherwise you could convert your script to Python 2.7.

Categories