I have an isolated Wintel host not able to pip or etc, which equals to have network opened to 'internet'.
I downloaded python embedded form python.org (on other machine), copied and unzipped it to O:\xip\Python on isolated machine.
Now it looks like:
libcrypto-1_1.dll
libffi-7.dll
libssl-1_1.dll
LICENSE.txt
pyexpat.pyd
python.cat
python.exe
python3.dll
python38.dll
python38.zip
python38._pth
pythonw.exe
select.pyd
sqlite3.dll
unicodedata.pyd
vcruntime140.dll
winsound.pyd
_asyncio.pyd
_bz2.pyd
_ctypes.pyd
_decimal.pyd
_elementtree.pyd
_hashlib.pyd
_lzma.pyd
_msi.pyd
_multiprocessing.pyd
_overlapped.pyd
_queue.pyd
_socket.pyd
_sqlite3.pyd
_ssl.pyd
i have PyPI requests package, did python setup.py install it on other machine and i copied \build\lib\ directory (which appears) into isolated machine O:\xip\Python\build\lib\requests\
my PATH have O:\xip\Python;O:\xip\Python\build\lib
my PYTHONPATH have O:\xip\Python\python38.zip;O:\xip\Python\build\lib;O:\xip\Python\build\lib\requests
When i go to python console and run import requests i get no module named 'requests'
1. Should I unzip this python38.zip?
2. should i have something more in PATH or PYTHONPATH?
3. Should i copy something more from machine where i did install of request package?
Any ideas what is wrong here?
The embedded distribution does not use environment vars. See here: Python Issue 28245
You should edit the python._pth file and put your additional paths there.
Alternatively, you could also extend sys.path before attempting the import.
Related
I have downloaded a python package to install, on my ubuntu machine. The package has already a setup.py file to use, but I want to change the default python installation address to something else, for this package specifically (and not for good). So what I tried is:
First in the terminal, I export that address of the new folder:
export PYTHONPATH=${PYTHONPATH}:${HOME}/Documents/testfolder/lib/python2.7/site-packages
Then I add this exported address as prefix to the installation command:
python setup.py install --prefix=~/Documents/testfolder
The installation goes through. Now to make python always look for this new path as well (next to the default installation path), I export the address in bashrc file:
export PYTHONPATH="${PYTHONPATH}:~/Documents/testfolder/lib/python2.7/site-packages"
But now whenever I open a terminal and try to import the installed package, it cannot see ("no module named..."). Only when I open a terminal in the folder where I had the installation files (namely setup.py), and run python, can it then see the package, and it works there.
Why isn't my export in bashrc making the package available from anywhere?
Is there something I have done wrong in the above?
To answer your question about the export path. Do you have $PYTHONPATH as a part of your $PATH? If not you should add it to path.
The best way to handle this scenario in my opinion is to use a virtual python environment. There are a couple to choose from, but I like virtualenv the best. The reason to take this approach is because you can manage different versions of python in separate folders. And have separate packages installed in these folders. I recommend looking into it as it is a very useful tool. If you want an examole of how to use it i can provide that https://virtualenv.pypa.io/en/stable/
I downloaded a python module from online and want to use it in IDLE, but I keep getting an error message saying it's not found.
My python path is "/Library/Frameworks/Python.framework/Versions/2.7/bin". If I want to be able to run modules I downloaded from online into IDLE, what should I set my python path to to be able to do that?
I am running OsX 10.10.5
Create a directory somewhere under your home directory. Let's say it's ~/pylib. Copy the module to ~/pylib. Before running IDLE execute the command
export PYTHONPATH=~/pylib
You should now be able to import the module.
If a module you have downloaded was properly packaged, it should come with the installation routine. Conventionally, it is called setup.py. If you see this file, you can just do
python setup.py install
That should take care of most packages available online and you don't even need to figure out where it was installed to.
If you really need to check/set the paths, you can check the directories as reported by
import sys
sys.prefix
sys.exec_prefix
These are the paths that point to the directories where stuff is installed (prefix/lib).
If you are looking into custom or user installation (using --user flag), check this folder: userbase/lib/python<VERSION>/site-packages
More details in the documentation.
I am running web2py on a Windows machine.
I'm working on an application, but it keeps erroring because it says the module I'm trying to use isn't installed. It is however installed in my local python install.
How can I install modules so that web2py can recognize them?
web2py recognize any module you have in your local Python installation, unless you have a module with the same name under /modules folder of your application.
If you are on windows I do not recommend the use of .exe version of web2py (this version is only for studies) and it has a self contained isolated Python interpreter.
Make sure you are using source version of web2py and Python 2.5+ on your windows.
web2py should import any module from your Python path, also you can drop modules in app/modules folder ], then web2py will check there first when import something.
If you are using the Windows binary version (i.e., web2py.exe), note that it includes its own Python interpreter, which means it will not use your installed version of Python and will therefore not see any of your installed modules. You can put Python modules in the /web2py/site-packages folder (which is created the first time you run the binary version), but the better approach is probably just to run the source code version of web2py. It's just as easy -- simply download and unzip the source code package, and instead of clicking on web2py.exe, you click on web2py.py (or at a command prompt, cd to the web2py directory and enter python web2py.py).
What about add your local module path into sys.path variable?
sys.path.apend('/path/to/your/module/directory')
By the way, which module is not found by web2py
I'm under the impression that Python import is supposed to automatically
unzip egg files in site-packages.
My installation doesn't seem to want to auto-unzip the egg. What I tried:
(1) I used easy_install to install the suds module, which copied the
egg file into site-packages. Python couldn't import it. (import suds)
(2) Then I used the --always-unzip option to easy_install. This time it
gave me a directory instead of a zip file. Python still couldn't import the suds module.
(3) I renamed the directory suds. still couldn't find it.
(4) finally I copied the suds directory out of the unzipped egg directory into
site-packags and Python found it (no surprise there).
for me, easy_install wasn't. What's missing here?
Rufus
By default (if you haven't specified multi-version mode), easy_installing an egg will add an entry to the easy-install.pth file in site-packages. Check there to see if there's a reference to the suds egg. You can also check the Python import path (which is the list of places Python will search for modules) like this:
import sys
print sys.path
Did you try import suds in a Python shell that was started before you easy_installed suds?
That would explain the behaviour you saw. The .pth files are only read at Python startup, so the egg directory or zip file wouldn't have appeared in sys.path. Copying the suds dir from inside the egg directory worked because site-packages itself was already in sys.path. So make sure you restart Python after installing an egg.
Python will import from zip archives, but it won't unzip the archive into site-packages. That is, it won't leave the unzipped directory there after you import. (I think it reads from the zip file in-place without extracting it anywhere in the file system.) I've seen problems where some packages didn't work as zipped eggs (they tried to read data from their location in the file-system), so I'd recommend always using the --always-unzip flag as you do in (2).
You haven't given the command lines you used. Did you specify the -m option to easy_install? That will cause the egg to be installed in multi-version mode. It won't be in sys.path by default, and you'd need to use the pkg_resources.require function before trying to import it.
I have installed Jython, a virtualenv named "jython-env" and have installed "bottle" for doing some web application development. I have to use some JAR files in this application for consumption by some Python code. I know I have to set the classpath which should include these JAR files. I tried setting the classpath using
export classpath=/home/myname/jclasses/foo.jar
but when I try to import the class, it says module not found. I am very new at Java and am doing this for the first time.
Can't the configuration be done such that I can just put the JAR files in the sitepackages directory of my virtualenv and use it from there?
jython -Dpython.path=/path/to/myjar.jar
Here's another idea: you could use a .pth file.
Create a file - /path/to/jythonenv/Lib/site-packages/myjars.pth:
path/to/jar1.jar
path/to/jar2.jar
Would also do the trick.
I'd like to suggest jip for you. With jip, you can manage your Java dependencies and classpath just like pip does for you.
pip install jip
Install a JAR file with dependencies,
jip install org.springframework:spring-core:3.0.5.RELEASE
Run with classpath configured,
jython-all your-python-file.py
Check http://pypi.python.org/pypi/jip for details.