How to install Numpy without compiling the sources - numpy

I have a project running on CentOS7 that uses Numpy.
The problem is that it takes a very huge amount of time to install this dependency.
I therefore tried to yum install numpy libs before pip install it.
So I run:
yum install numpy-1.7.1
pip install numpy==1.7.1 # This pip is executed in a virtualenv
The yum install installs the packaged library, and is quite fast to be performed.
The weird thing is that the pip install command re-compile all the sources. This is strange because, from my understanding, the pip install shall only add the python bindings on the compiled lib previously installed.
Any idea to get this library installed without to have everything recompiled?

I solved it by symlinking the 'global lib' (installed by yum install) into the virtual env:
ln -s /lib64/python2.7/site-packages/numpy $VENV/lib64/python2.7/site-packages/numpy
ln -s /lib64/python2.7/site-packages/numpy-1.7.1-py2.7.egg-info $ENV/lib64/python2.7/site-packages/numpy-1.7.1-py2.7.egg-info

Related

Python3.10 source venv has changed

I went to do some python leetcode on a personal repo and after I upgraded my Kubuntu to 22.04 I realized the current venv wasn't working.
I had figured I would need to recreate the venv.
Installed python3.10-venv but I cant source and activate it.
In fact venv/bin/activate doesn't exist anymore.
The folder only contains three files
python python3 python3.10
I had tried but no dice
source venv/bin/python3.10
So naturally source venv/bin/activate doesn't work. Ideas?
I've installed Ubuntu 22.0.4 and I've had the same problem as yours and I solved that problem in this way.
install venv:
sudo apt-get update
sudo apt-get install python3-virtualenv
Create venv:
virtualenv --python=/usr/bin/python3.10 (VENV-NAME)
python3.10 -m venv (VENV-NAME)
source (VENV-NAME)/bin/activate
check & update pip:
pip list
and update pip for example(in my pc):
(/home/amin/Desktop/prog/Django/moein/coffeinrider.com/Project/A/(VENV-NAME)/bin/python3.10 -m pip install --upgrade pip)
When trying to create a virtual env using venv for Python, a version of Python that is already installed system-wide must be used, but a version of the venv library from the system must also be used. These are two pre-requisites for setting up a virtual environment.
WARNING: I did this in a hurry because I needed it but please be warned: this may break your system Python with a result that applications that rely on it may break.
The problem I had, matching symptoms given here, seems to be that when trying to create a venv using Python 3.10.8, the venv module for Python 3.8.10 was being used.
So, given Python 3.8 and Python 3.10 are already installed using apt, first of all I uninstalled these packages:
sudo apt purge python3-venv python3.8-venv
sudo apt autoremove
Then I linked python3 to point to Python 3.10:
cd /usr/bin
sudo rm python3
sudo ln python3.10 python3
Then I installed the venv for Python3.10:
sudo apt install python3.10-venv
This now means creating a virtual environment for Python 3.8 doesn't work (because Python3.8 venv has just been removed). I'm not sure if there is a means to have them both working, and I haven't yet tried to just install python3.8-venv again and try them both, as I need my 3.10 environment working quickly, right now ;-). But it seems possible there has been some conflict introduced when following the usual upgrade route within Ubuntu 20.
However, venv for Python 3.10 should now work as expected:
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ python -V
Python 3.10.8
(.venv) $ pip install --upgrade pip
...
(.venv) $ pip list
Package Version
---------- -------
pip 22.3
setuptools 63.2.0
It has been updated to source venv/local/bin/activate

How to install tensorflow on m1 mac using pipenv

In our project we use pipenv and I can't switch everyone on conda.
I'm using python 3.9 and pipenv. I tried to install pipenv inside conda env, but it didn't work well
Ensure you have Xcode Command Line Tools installed by executing xcode-select -p.
Install HDF5 library using Homebrew and h5py without binaries.
brew install hdf5
export HDF5_DIR="$(brew --prefix hdf5)"
export PIP_NO_BINARY=h5py && pipenv install h5py
Install TF
pipenv install tensorflow-macos
pipenv install tensorflow-metal
Skip tensorflow-deps and install any missing libraries manually. You can find some more details in this blog post.

install rule of python based packages on Debian 9

In order to install matplotlib in Debian 9 should I issue
sudo apt-get install python3-matplotlib
or
pip3 install matplotlib?
What is the preferred way? Let me add more detail.
'man pip3' says
pip is a Python package installer, recommended for installing Python
packages which are not available in the Debian archive.
matplotlib confirms this
To install Matplotlib at the system-level, we recommend that you use
your distribution's package manager. This will guarantee that
Matplotlib's dependencies will be installed as well.
According to this I shall run apt-get. However, I had a similar case with numpy. 'import numpy' worked after 'pip3 install numpy'.
Using
Debian GNU/Linux 9.6 (stretch)
$ python3 -V
Python 3.5.3
The key quote from man pip3 is:
recommended for installing Python packages which are not available in the Debian archive.
You can check whether a package is available in the Debian archive by issuing an apt search command, eg.
apt search matplotlib
If your system already has all the necessary dependencies then installing a package with pip will work (as you experienced with pip install numpy).
If you do not have the necessary dependencies your distribution’s package manager will install them automatically. However, this is not true of pip: you would need to resolve any dependency issues manually. In the case of matplotlib, you can find a list of the dependencies you'd need to install manually here.
Essentially, using your system package manager to install a package takes away the extra work of ensuring you have all the necessary dependencies for that package.
pip comes into its own if you desire to work with virtual environments.

Downloading PostgreSQL Mac Download Error

could you please advise me of a solution you may know for downloading PostgreSQL. I am trying to install 9.6.5 version, but also tried the 10.0, same error.
I am using an installation option for Mac operating system OS Sierra from website: https://www.openscg.com/bigsql/postgresql/installers.jsp/
I am getting an error:
Have tried to run the instruction sudo easy_install pip in the command line and it installs the pip file successfully. However I am still unable to install the PostgreSQL.
Please could you advise what the issue may be?
I have also installed Homebrew (it did not help).
I do already have anaconda and Python installed, as well as latest versions of R and RStudio.
I have now found a solution to the above problem (on Mac). Execute the following command in your terminal:
sudo easy_install-2.6 pip
If that does not work execute:
sudo easy_install-2.7 pip
This allows the PostgreSQL to be downloaded correctly.
I followed the instructions suggesting using easy_install-2.7 but still got an error very similar to that from the OP. I had to specifically install pip 9.0.0 with
sudo easy_install-2.7 pip=9.0.0
after which the PostgreSQL install worked.
The default pip is now v10, so it's probably a string compare issue in the installer.
Here is the solution that worked for me on Mac High Sierra 10.13.4:
Clear out the brew cache $ rm -rf ~/Library/Caches/Homebrew
Clear out the site-packages $ sudo rm -rf /usr/local/lib/python2.7/site-packages
Reinstall Python $ brew reinstall python This pulls down python-3.5.6.high_sierra and put it in /usr/local/bin/python3
But which python still shows /usr/bin/python
The solution is to run $ brew install python#2 which pulls down python#2-2.7.14_3.high_sierra
Now which python shows the correct path /usr/local/bin/python which is also where all your pip stuff is installed, so now pip will work.
Ensure the latest version of pip is installed with $ sudo pip install --upgrade pip

lxml won't install under pypy using easy_install

When doing:
$ sudo pypy -m easy_install lxml
The response is:
Searching for lxml
[...snip...]
ERROR: /bin/sh: 1: xslt-config: not found
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
/usr/lib/pypy/lib-python/2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
warning: no files found matching '*.txt' under directory 'src/lxml/tests'
src/lxml/lxml.etree.c:8:22: fatal error: pyconfig.h: No such file or directory
compilation terminated.
error: Setup script exited with error: command 'cc' failed with exit status 1
At the same time, sudo pip install lxml works fine.
What's going on?
Thanks.
sudo apt-get install python-dev fixed it for me on ubuntu 13.04
$yum install python-lxml or apt-get install python-lxml
this solved mine.
I've stumbled with this trouble a couple of times.
Short answer
Python2: $ python2.7 setup.py clean build --with-cython install
Python3: $ pip-3.3 install lxml
Long answer
The hypothesis is that pip install lxml should work in every environment, regardless if you are using Python2 or Python3.
There's also Cython to be considered: You will certainly enjoy lxml compiled with Cython due to relevant performance gains.
For reasons unknown to me, the compilation on Python2 does not find Cython.
To be more precise and absolutely explicit about this matter, both commands below DO NOT employ Cython:
# DO NOT use these commands. I repeat: DO NOT use these commands.
$ pip-2.7 install lxml
$ easy_install-2.7 install lxml
So, when using Python2 you have only one alternative, as far as I know, which is: compile from sources, Luke!
# install build environment and dependencies
$ kernel_release=$( uname -r )
$ sudo apt-get install linux-headers-${kernel_release} build-essential -y
$ sudo apt-get install libxml2-dev libxslt1-dev -y
# Download from github and compile from sources
$ git clone --branch lxml-3.2.4 https://github.com/lxml/lxml
$ python2.7 setup.py clean build --with-cython install
I've handled this problem by installed Ubuntu package pypy-dev.