I have written a utility script for some of my colleagues' Mac OSX with Python 2.6.1. Since they don't have all the required modules installed, I have a try-except import clause:
try:
import argparse
except ImportError:
print "argparse module missing: Please run 'sudo easy_install argparse'"
sys.exit(1)
I'm pretty sure there are more elegant ways to handle this. Any ideas?
Your best shot is to freeze your python code with all modules needed and distribute it as binary; it worked for me with Windows and Linux, however on Linux, make sure you have a compatible glibc version
There are some freeze tools for Mac OS X, but I have not used them. I only used Windows and Linux tools.
check out this link for more info
http://hackerboss.com/how-to-distribute-commercial-python-applications/
That is the common idiom but you can use setuptools and pip to automate the installation of dependencies (example).
This is actually the best way to do it. The same approach is for example used to select different json libraries depending on what's installed on the machine:
try:
import simplejson as json
except ImportError:
import json
Related
Nube at Python but application I want to use is written in it and I am having trouble getting this application to work.
I have been searching for answers but perhaps don't know enough to ask the right questions.
I am running windows 10 (new to it also). I have installed Python 3.10.1 from the Windows store. It is in the path statement and does execute from cmd prompt.
As my application uses YAML I have also installed PyYaml,
I have no idea if it installed correctly, where it is installed and it is not in the PATH.
My application called wireviz.py is launched from its source folder by typing wireviz -V. It fails at line 10 with ModuleNotFoundError: No module named 'yaml'.
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 import argparse
5 import os
6 from pathlib import Path
7 import sys
8 from typing import Any, Tuple
9
10 import yaml
I know much more may be needed, but frankly I don't know
what and maybe even how to get it.
The error message indicates that PyYAML is not installed; since PyYAML is registered under the Python Package Index (PyPI) as yaml, you should install it using pip (the Python package installer). The command might look like this:
pip install yaml
There are many more nuances to learn about package installation, but for the time being this should get you up and running.
Problem solved thanks to Austin advise.
Because of it I did some research on Python Installer to get a better feel for the process.
Found my stuff was installed all over the place.
Found a pip package for my application so I deleted everything including Python and did a fresh install of Python and the "Graphviz" applications.
Then installed my application (WireViz.py) using pip install.
Application and all required modules installed without error and after checking PYTHONPATH, everything is now working.
Thanks for the help.
I just want to install the suds library, but suddenly it wasn't proceeding because it was not finding the os library, so I tried to open my python and it results me an error. When I import the os library and there are some errors during the opening as well. Please, see the snapshot of my error when importing the library mentioned.
Is there any solution for this? Or do I need to reinstall python?
You need to install a more recent version of Python - version 2.7.12 or later. All versions of Python 2.6 have been end-of-lifed and any use of Python 2.6 is actively discouraged.
I got this simple problem and I can't find the answer anywhere, I'm wasting a lot of time!
I did a Python programm on Linux (which works OK), but when I try to run it on Windows, there are too problems with libs...
I have installed the libs I need (dateutil, lxml, xmlrpclib...) in C:\Python34\Lib\site-packages. But then, they don't work as they do on Linux. For example:
from dateutil.tz import tzlocal
Gives me next error:
File "C:\Python34\lib\site-packages\dateutil\tz.py", line 9, in module
from six import string_types, PY3 ImportError: No module named 'six'
That is, they are not finding the other modules... why???
Have you try this ?
http://www.instructables.com/id/How-to-install-Python-packages-on-Windows-7/
Maybe it can help
It looks like you're using Python 3.4 which comes with pip. pip is a tool for installing packages and any dependencies they might have (like the srting_types module from your error message). I'd suggest learning how to use it because it resolves most of the packaging problems with you needing to moving things around yourself. See an answer from a different question to learn more about pip.
There are some packages that need to be compiled. This can be difficult on Windows 7 if you don't have the proper toolchain set up to compile packages. I'd recommend Christoph Gohlke's wonderful collection of installable packages for Windows. You just need to make sure to grab the right version. Since 3.4 is still relatively new, some packages may not be available, so be warned.
Hello I'm trying import a module import Image. I recieved this error <type 'exceptions.ImportError'> Cannot import module 'Image'
I looked for a solution and found this Install Python Module in local install of web2py
So "how can I drop modules in app/modules folder" so web2py will check there first when import something or if anyone knows a better solution then the provided solution please help.
If you are using the Windows or Mac web2py binary, they include their own Python interpreter, so they will not use your system's installed version of Python nor see any of its modules. If you have your own version of Python installed, you're better off running web2py from source, which is just as easy (just download and unzip -- run with the web2py.py file rather than web2py.exe or web2py.app).
I'm just starting out with Python, and have found out that I can import various libraries. How do I find out what libraries exist on my Mac that I can import? How do I find out what functions they include?
I seem to remember using some web server type thing to browse through local help files, but I may have imagined that!
From the Python REPL (the command-line interpreter / Read-Eval-Print-Loop), type help("modules") to see a list of all your available libs.
Then to see functions within a module, do help("posix"), for example. If you haven't imported the library yet, you have to put quotes around the library's name.
For the web server, you can run the pydoc module that is included in the python distribution as a script:
python /path/to/pydoc.py -p 1234
where 1234 is the port you want the server to run at. You can then visit http://localhost:1234/ and browse the documentation.
Every standard python distribution has these libraries, which cover most of what you will need in a project.
In case you need to find out if a library exists at runtime, you do it like this
try:
import ObscureModule
except ImportError:
print "you need to install ObscureModule"
sys.exit(1) # or something like that
You can install another library: yolk.
yolk is a python package manager and will show you everything you have added via pypi. But it will also show you site-packages added through whatever local package manager you run.
just run the Python interpeter and type the command
import "lib_name"
if it gives an error, you don't have the lib installed...else you are good to go
On Leopard, depending on the python package you're using and the version number, the modules can be found in /Library/Python:
/Library/Python/2.5/site-packages
or in /Library/Frameworks
/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages
(it could also be 3.0 or whatever version)...
I guess it is quite the same with Tiger
Considering that in every operating system most of python's packages are installed using 'pip' (see pip documentation) you can also use the command 'pip freeze' on a terminal to print a list of all the packages you have installed through it.
Other tools like 'homebrew' for macOS (used when for some reason you can't install a package using pip) have similar commands, in this specific case 'brew list'.