Install python package from bitbucket in non-editable mode - python

I'm trying to install a python package from a private bitbucket repository into a virtual env, but pip does not seem to install any files. When using the following command (norman is the package's name):
pip3 install git+ssh://git#bitbucket.org/mycompany/myrepo.git#develop#egg=norman
the installation is successful but there is no norman folder in venv/lib/python3.6/site-packages/, so it seems that nothing was installed, even if venv/lib/python3.6/site-packages/norman=0.1.0.dist-info is indeed there.
Yet, the installation works perfectly using a tar.gz archive made with python3 setup.py sdist then installing with pip3 install path_to_norman.tar.gz.
Following these indications, I also tried to install the package in editable mode :
pip3 install -e git+ssh://git#bitbucket.org/mycompany/myrepo.git#develop#egg=norman
This worked fine and installed the files (in venv/src), but I'd prefer installing it in non-editable mode. What should I do to make the installation work in non-editable mode ?

The problem came from python __init__.py files which were not included in the remote repo, so the package installed by pip3 install git+ssh... was actually empty.
When building the archive on a local machine, they were obviously there, and when using -e option, as the whole repo is downloaded, the python scripts were there anyway.
When not using -e, from what I understand, pip creates a temporary local download of the files available and then builds the package normally. Since init files were not downloaded, python scripts were not recognized by setuptools, thus an empty package was installed.

Related

How to create a common environment for teamwork in Python

I would like to create a virtual environment for my team. My team, works in different places and everyone has their own environment, it causes a lot of problems, everyone has a different version of the libraries (Python, RobotFramework).
I thought about:
creating one common environment, I used virtualenv.
Installing the prepared libraries (python and robotframework) with one command pip install ...,
Prepared libraries will be in the git repository so that everyone can modify them, change the library version.
I have the first and third parts done, but I have a problem with the second. How to create such a package of libraries to be able to install it with one pip install command.
Should I create an environment locally, install all the libraries in it, and send them to git? Or should I package the project via setuptool (to tar.gz)?
Unfortunately, I cannot find the answer to this question, it seems to me that none of the above solutions is optimal.
The easiest way of doing it would be creating a text file of all the libraries you are using in pip with the command.
pip freeze > requirements.txt
This will create a file listing all the packages with their versions that are being used. To install that ask every team member to place that requirement file in their projects and use
pip install -r requirements.txt
With pip, you could download your dependencies. These will be .tar.gz, .whl or .zip files. Note that this could be complicated if your team uses multiple OS.
Here is an example which will download the dependencies into the directory named "dependencies", you can push this to git along with the requirements file.
pip freeze > req.txt
pip download -r req.txt -d dependencies
When someone clones your repository, they can install the dependencies offline with the following command.
pip install --no-index --find-links=dependencies -r req.txt

Installing all the wheel packages in a directory is not working in Windows OS

I'm trying to clone all the packages of a venv from one PC to another(both having Windows OS). When I'm installing all the wheel packages on the second PC with this command
pip install *.whl
as suggested by AKX in his answer to my question, it's giving me the error as.
*.whl looks like a file but not found in the current directory.
When I installed a package that have no dependencies, it's installed successfully.
There is a long list of packages, so I can't install each package by typing the name of whole .whl file.
If you have access to a bash shell (Git Bash, Cygwin, WSL, or whatever), the following script works great:
for wheel in *.whl do
pip install $wheel
done
I'm sure similar syntax could be used for Powershell.

Installing Django and related packages on an offline computer

I'm using win7, python 2.7 and I have a project with several packages running.
I wanted to move the project to my friends laptop (which can't access to internet, not an option). so I downloaded Python/Django/All required packages, Installed python and run python setup.py install in each package directory.
I've found that some packages, even after I download them, requires somethings from the internet to be downloaded and causes error. so:
How can I download a package and all it's dependencies or what ever it needs to be installed offline?
This is how you can do it
Install Django and all related packages to a Python virtual environment
Run pip freeze > requirements.txt which will list all installed packages and their versions in this file
Use pip wheel -r requirements.txt command which builds a wheelhouse folder of the package list
Zip this folder
Go to your friend's computer, unzip
create virtual environment and run pip install wheelhouse/* (Install all packages from the wheelhouse)
More about pip wheel.
Python and pip needs to be separately copied and installed.

Python: PIL/_imaging.so: invalid ELF header

I'm using a virtualenv to run Python 2.7 in my local machine and everything works as expected. When I transfer "site-packages" to my production sever, I get the follow error:
PIL/_imaging.so: invalid ELF header
This happens on the Pillow 2.5.3 pypi package found here
I am running OS X, while my production server is running Debian. I suspect the OS differences might be causing the issue but I'm not sure. I have no idea how to fix this. Can anyone help?
Note: I cannot install packages directly to my production server, so I have to upload them directly to use them.
In your current virtual environment, execute the following command
pip freeze > requirements.txt
Copy this requirements.txt file to your server.
Create your new virtualenvironment (delete the one you were using before).
Activate the virtual environment and then type pip install -r requirements.txt
Now, the libraries will be installed correctly and built accurately as well.
If you see errors for PIL, execute the following commands:
sudo apt-get install build-essential python-dev
sudo apt-get build-dep python-imaging
virtual environments are for isolating Python on your current machine; they are not for creating portable environments. The benefit is to work with different versions of Python packages without modifying the system Python installation.
Using virtual environments does not require super-user permissions; so you can install packages even if you are not "root".
It does, however, require Internet access as packages are downloaded from the web. If your server does not have access to the Internet, back on your mac, do the following, from your virtual environment:
pip install basket
This will install basket which is a small utility that allows you to download packages but not install them. Great for keeping a local archive of packages that you can move to other machines.
Once its installed, follow these steps as listed in the documentation:
basket init
pip freeze > requirements.txt
awk -F'==' '{print $1}' requirements.txt | basket download
This will download all the packages from your requirements.txt file into ~/.basket
Next, copy this directory to your server and then run the following command from your virtualenvironment
pip install --no-index -f /path/to/basket -r requirements.txt

Can pip copy dependency source into my virtualenv?

I am a bloody beginner in Python and Django. To set up a environment on my Windows machine, I performed the following steps.
Install Python 3.4
Use pip to install virtualenv
Create a project folder and set up a virtualenv there
Download Django 1.7b1 release from the official site
Extract the archive in my downloads folder
Install it into my virtualenv
For the last step, I used pip from my virtualenv.
[project]\scripts\pip.exe install -e [downloads]\Django-1.7b1
From the global python interpreter I can't import django, as expected. When using the python executable from the virtualenv, it works. But the import only succeeds as long as I have the Django source in my downloads folder. Instead, I would like to include it into my virtualenv.
Can I make pip to automatically copy the Django source into my project folder?
Install django via pip inside the virtualenv. I'm running Linux but you should be able to run the commands on windows.
If you need a version that's not in PyPi, download the package and install it to the virtualenv site-packages-folder.
My site-packages folder for project is in ~/venvs/project/lib/python2.7/site-packages.
To install there:
pip install downloads/Django-1.7b1.tar.gz -t ~/venvs/project/lib/python2.7/site-packages
Django will install to the site-packages folder and is now importable from within the virtualenv. Downloads/Django-1.7b1 is no longer needed.
Below is an example where I'm installing Django 1.7b1 from a local archive to the site-packages-folder of my virtualenv:
(project)msvalkon#Lunkwill:/tmp$ pip install /tmp/Django-1.7b1.tar.gz -t ~/venvs/project/lib/python2.7/site-packages/
Unpacking ./Django-1.7b1.tar.gz
Running setup.py egg_info for package from file:///tmp/Django-1.7b1.tar.gz
-- SNIP --
Successfully installed Django
Cleaning up...
(project)msvalkon#Lunkwill:/tmp$ python -c "import django;print django.get_version()"
1.7b1
(project)msvalkon#Lunkwill:/tmp$ deactivate
# I've got a really old version installed globally, but you can see
# that the installation worked.
msvalkon#Lunkwill:/tmp$ python -c "import django;print django.get_version()"
1.5.1
After this you should find the following output when doing pip freeze while the virtualenv
is activated:
(project)msvalkon#Lunkwill:/tmp$ pip freeze
Django==1.7b1
argparse==1.2.1
wsgiref==0.1.2

Categories

Resources