No module named numpy in Flask - apache

I need to use Numpy on EC2 instance that runs Flask with WSGI-py3, which can be accessed over HTTP.
After setting up everything needed, I can see the page in the browser. However, later I am installing Numpy using pip3 and now the service breaks with the following error in /var/log/apache2/error.log ModuleNotFoundError: No module named 'numpy', however I can import numpy in python3 without any problems
What could be done to be able to import numpy in Flask application?
EDIT:
It is confusing.. If I list all Python versions installed, I get:
0 lrwxrwxrwx 1 root root 9 Oct 25 2018 /usr/bin/python3 -> python3.6
0 lrwxrwxrwx 1 root root 16 Oct 25 2018 /usr/bin/python3-config -> python3.6-config
4 -rwxr-xr-x 1 root root 1018 Oct 28 2017 /usr/bin/python3-jsondiff
4 -rwxr-xr-x 1 root root 3661 Oct 28 2017 /usr/bin/python3-jsonpatch
4 -rwxr-xr-x 1 root root 1342 May 1 2016 /usr/bin/python3-jsonpointer
4 -rwxr-xr-x 1 root root 398 Nov 15 2017 /usr/bin/python3-jsonschema
4424 -rwxr-xr-x 2 root root 4526456 Apr 18 01:56 /usr/bin/python3.6
0 lrwxrwxrwx 1 root root 33 Apr 18 01:56 /usr/bin/python3.6-config -> x86_64-linux-gnu-python3.6-config
4424 -rwxr-xr-x 2 root root 4526456 Apr 18 01:56 /usr/bin/python3.6m
0 lrwxrwxrwx 1 root root 34 Apr 18 01:56 /usr/bin/python3.6m-config -> x86_64-linux-gnu-python3.6m-config
0 lrwxrwxrwx 1 root root 10 Oct 25 2018 /usr/bin/python3m -> python3.6m
0 lrwxrwxrwx 1 root root 17 Oct 25 2018 /usr/bin/python3m-config -> python3.6m-config
pip3 seems to be connected to python3.6
/usr/local/bin/flask uses #!/usr/bin/python3
If I install numpy using /usr/bin/python3 -m pip install numpy I still have the same problem

This probably means, the Python interpreter which runs Flask is a different than the Python interpreter which you have installed numpy into.
Unfortunately, I have no experience with AWS.
Basically, you have to figure out how to find the Python interpreter you installed Flask with.

Using virtual environment in EC2 has helped:
sudo apt-get update
sudo apt-get install apache2
sudo apt-get install libapache2-mod-wsgi-py3
sudo apt-get install python3.6
sudo ln -sT /usr/bin/python3 /usr/bin/python
sudo apt-get install python3-pip
sudo ln -sT /usr/bin/pip3 /usr/bin/pip
sudo pip install flask
sudo apt-get install virtualenv
mkdir ~/flaskapp
sudo ln -sT ~/flaskapp /var/www/html/flaskapp
cd ~/flaskapp
virtualenv flask --python=python3
sudo vim /etc/apache2/sites-enabled/000-default.conf:
.....
sudo pip3 install numpy
...

Related

Homebrew: how to remove redis/4.0.2 and use redis#3.2 as my default redis

I started this quest with redis/3.0.3 installed, and looking to upgrade my local dev redis to version 3.2.3, which is what we're running in production. I ultimately ran brew upgrade redis, which installed redis 4.0.2, ahead of my desired version. Then I found that you can install 3.2.x with brew install redis#3.2. Also, while trying to cleanup 4.0.2, instead it cleaned up only 3.0.3.
Now I'm stuck in a situation where Homebrew won't allow me to uninstall redis/4.0.2, and views redis#3.2 as a separate Homebrew Formula.
$ brew switch redis 3.2
Error: redis does not have a version "3.2" in the Cellar.
Versions available: 4.0.2
See how in the Cellar, they're showing as separate Formulae here:
$ ls /usr/local/Cellar/ | grep redis
redis
redis#3.2
What is the correct "Homebrew" way to remove redis/4.0.2 and use redis#3.2 as my default redis, so that commands to redis-server and redis-cli reference 3.2 instead? I'm running Mac OS X Yosemite 10.10.5 and Homebrew 1.3.4.
$ ls -l /usr/local/bin/ | grep redis
lrwxr-xr-x 1 jsoro wheel 41 Oct 5 12:51 redis-benchmark -> ../Cellar/redis/4.0.2/bin/redis-benchmark
lrwxr-xr-x 1 jsoro wheel 41 Oct 5 12:51 redis-check-aof -> ../Cellar/redis/4.0.2/bin/redis-check-aof
lrwxr-xr-x 1 jsoro wheel 41 Oct 5 12:51 redis-check-rdb -> ../Cellar/redis/4.0.2/bin/redis-check-rdb
lrwxr-xr-x 1 jsoro wheel 35 Oct 5 12:51 redis-cli -> ../Cellar/redis/4.0.2/bin/redis-cli
lrwxr-xr-x 1 jsoro wheel 40 Oct 5 12:51 redis-sentinel -> ../Cellar/redis/4.0.2/bin/redis-sentinel
lrwxr-xr-x 1 jsoro wheel 38 Oct 5 12:51 redis-server -> ../Cellar/redis/4.0.2/bin/redis-server
The issue was trivial and could have been easier if the Brew Docs/FAQs were more clear. The Brew FAQs say that uninstalls are handled by brew cleanup <formula>, which is what caused my redis/3.0.3 to be removed. However, brew cleanup would not remove redis/4.0.2. To remove it I used brew uninstall, which I could not find in the Docs...
$ brew uninstall redis
Uninstalling /usr/local/Cellar/redis/4.0.2... (11 files, 2.7MB)
Then, to fix the remaining issue of redis#3.2 not being symlinked under /usr/local/bin/, I first tried an uninstall/re-install of redis#3.2 to see if Homebrew would take care of it...
$ ls -l /usr/local/bin/ | grep redis
$ brew uninstall redis#3.2
Uninstalling /usr/local/Cellar/redis#3.2/3.2.11... (11 files, 1.7MB)
$ brew install redis#3.2
==> Downloading http://download.redis.io/releases/redis-3.2.11.tar.gz
## TRIMMED ##
==> Summary
🍺 /usr/local/Cellar/redis#3.2/3.2.11: 11 files, 1.7MB, built in 10 seconds
Of course, this did not create the symlinks--actually the Caveats section which I trimmed away from the output says this explicitly with suggestions. Instead of using their suggestion, I opted to create symlinks manually:
$ cd /usr/local/bin/
$ ls -l | grep redis
$
$ ln -s /usr/local/Cellar/redis\#3.2/3.2.11/bin/redis-check-aof redis-check-aof
$ ln -s /usr/local/Cellar/redis\#3.2/3.2.11/bin/redis-check-rdb redis-check-rdb
$ ln -s /usr/local/Cellar/redis\#3.2/3.2.11/bin/redis-cli redis-cli
$ ln -s /usr/local/Cellar/redis\#3.2/3.2.11/bin/redis-sentinel redis-sentinel
$ ln -s /usr/local/Cellar/redis\#3.2/3.2.11/bin/redis-server redis-server
$ ls -l | grep redis
lrwxr-xr-x 1 jsoro wheel 54 Oct 5 14:27 redis-check-aof -> /usr/local/Cellar/redis#3.2/3.2.11/bin/redis-check-aof
lrwxr-xr-x 1 jsoro wheel 54 Oct 5 14:27 redis-check-rdb -> /usr/local/Cellar/redis#3.2/3.2.11/bin/redis-check-rdb
lrwxr-xr-x 1 jsoro wheel 48 Oct 5 14:27 redis-cli -> /usr/local/Cellar/redis#3.2/3.2.11/bin/redis-cli
lrwxr-xr-x 1 jsoro wheel 53 Oct 5 14:27 redis-sentinel -> /usr/local/Cellar/redis#3.2/3.2.11/bin/redis-sentinel
lrwxr-xr-x 1 jsoro wheel 51 Oct 5 14:26 redis-server -> /usr/local/Cellar/redis#3.2/3.2.11/bin/redis-server
The last thing to note is that since I had run the redis-server while under the redis/4.0.2 version, the dump.rdb file was no longer compatible. Running redis-server using redis 3.2.x on a 4.x dump.rdb causes the server to exit immediately.
$ redis-server
## TRIMMED ##
38504:M 05 Oct 14:29:07.234 # Server started, Redis version 3.2.11
38504:M 05 Oct 14:29:07.259 # Can't handle RDB format version 8
38504:M 05 Oct 14:29:07.260 # Fatal error loading the DB: Invalid argument. Exiting.
Unfortunately you need to rm dump.rdb, or remove/rename the dump.rdb file, in order to get redis-server to start up again.

maxminddb module for apache 2.4 on ubuntu error: The MaxMind DB file contains invalid metadata

here is my system information:
$ apachectl -v
Server version: Apache/2.4.18 (Ubuntu)
Server built: 2016-07-14T12:32:26
$ cat /etc/*release* | grep -i dist
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
$ uname -r
4.4.0-57-generic
i wish to install mod_maxminddb. i installed geoipupdate as a prerequisites and configured it to include not only geolite database, but either commercial one (using this)
$ ls -l /etc/GeoIP.conf
-rw-r--r-- 1 root root 818 Dec 24 18:29 /etc/GeoIP.conf
$ ls -l /usr/share/GeoIP/
total 0
$ geoipupdate
$ ls -l /usr/share/GeoIP/
total 187444
-rw-r--r-- 1 root root 112192399 Dec 24 18:46 GeoIP2-City.mmdb
-rw-r--r-- 1 root root 3012279 Dec 24 18:46 GeoIP2-Country.mmdb
-rw-r--r-- 1 root root 47721533 Dec 24 18:46 GeoIPCity.dat
-rw-r--r-- 1 root root 1699494 Dec 24 18:45 GeoIP.dat
-rw-r--r-- 1 root root 4189407 Dec 24 18:45 GeoIPISP.dat
-rw-r--r-- 1 root root 4299547 Dec 24 18:45 GeoLiteASNum.dat
-rw-r--r-- 1 root root 17760694 Dec 24 18:45 GeoLiteCity.dat
-rw-r--r-- 1 root root 1054583 Dec 24 18:45 GeoLiteCountry.dat
then complied and installed the mod_maxminddb, and when apache is configured to use the commercial databases, the following error is thrown
$ apachectl -M
AH00526: Syntax error on line 12 of /etc/apache2/mods-enabled/maxminddb.conf:
MaxMindDBFile: Failed to open /usr/share/GeoIP/GeoIPCity.dat: The MaxMind DB file contains invalid metadata
but that is not the case when apache is configured to use the geolite databases.
any ideas?
You didn't include your Apache config, but you appear to be trying to use mod_maxminddb with GeoIPCity.dat (GeoIP Legacy). It only works with GeoIP2. Adjust line 12 of maxminddb.conf to use GeoIP2-City.mmdb instead.

I installed nodejs , but npm looks like not working( at embedded linux)

I installed Node.js.
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs (15.4MB)
I can find the Node.js npm.
root#linaro-server:/usr/bin# ll | grep node
lrwxrwxrwx 1 root root 22 Jan 24 10:31 node -> /etc/alternatives/node*
-rwxr-xr-x 1 root root 5996796 Jan 24 07:05 nodejs*
lrwxrwxrwx 1 root root 38 Jan 24 07:05 npm -> ../lib/node_modules/npm/bin/npm-cli.js*
# node -v
v0.10.25
# npm -v
no returns, it looks like npm not working.
How can I activate npm or reinstall npm.
Now, I run this command:
curl https://npmjs.org/install.sh | sh
but my linux prompt stop at
fetching: http://registry.npmjs.org/npm/-/npm-1.3.25.tgz
How can I manage this probelem?
I was confused the environment of nodejs.
My CPU is ARM.
uname -a
shows
Linux linaro-server 3.6.0-10612-g9d11689 #11 SMP PREEMPT Mon Dec 3 16:04:32 IST 2012 armv7l armv7l armv7l GNU/Linux
So I should compile node.js.
The following is my solution.
wget http://nodejs.org/dist/node-latest.tar.gz
tar zxvf node-latest.tar.gz
cd node-v*
./configure --without-snapshot --dest-cpu=arm --dest-os=linux
make
make install
the MAKE takes a time, but above steps show me the good result.
I can get normal return of node -v and npm -v.
root:/home/user01> node -v
v0.11.9
root:/home/user01> npm -v
1.3.15
node and npm was installed at /usr/local/bin
root:/usr/local/bin> ll | grep node
-rwxr-xr-x 1 root root 10912375 Jan 27 08:04 node*
lrwxrwxrwx 1 root root 38 Jan 27 08:04 npm -> ../lib/node_modules/npm/bin/npm-cli.js*
I referred this file :
http://events.linuxfoundation.org/sites/events/files/slides/nodejs-presentation_0.pdf

make: *** /lib/modules/2.6.32-279.el6.x86_64/build: No such file or directory. Stop

I downloaded the RALINK driver from their web site
untar -xvf rtl*
and then i ran "make" in it. google search suggested "kernel-devel"
needed to be installed.
i installed the kernel-devel package but i still get this error
make: *** /lib/modules/2.6.32-279.el6.x86_64/build: No such file or directory. Stop.
when i check to see if that file exists..
i cd into /lib/modules/2.6.32-279.el6.x86_64/
i believe this error happens right after "make" command tries to execute this command
make ARCH=x86_64 CROSS_COMPILE= -C /lib/modules/2.6.32-279.el6.x86_64/build M=/home/a/Desktop/3/rtl8712_8188_8191_8192SU_usb_linux_v2.6.6.0.20120405 modules
and it's there it is called "build"
so why is it saying no such file or directory ?
**EDIT**
If your problem is like the one I was having (see below), it seems the kernel development package isn't installed.
Try:
yum install kernel-devel
Original Message
I am having the same problem. But, interestingly, when I ls-l on the parent directory to the "missing directory" (so, ls -l /lib/modules/2.6.32-431.el6.x86_64/) it shows that build is a broken link pointing to /usr/src/kernels/2.6.32-431.el6.x86_64, but /usr/src/kernels/ is empty.
So, I don't know if this is much help, but hopefully it gives someone else a better idea of what's wrong.
[root#xx libreswan-3.7]# ls -l /lib/modules/2.6.32-431.el6.x86_64/
total 3524
lrwxrwxrwx. 1 root root 46 Dec 12 13:42 build -> ../../../usr/src/kernels/2.6.32-431.el6.x86_64
drwxr-xr-x. 2 root root 4096 Nov 21 22:41 extra
drwxr-xr-x. 11 root root 4096 Dec 12 13:42 kernel
-rw-r--r--. 1 root root 589679 Dec 12 13:43 modules.alias
...
-rw-r--r--. 1 root root 851070 Dec 12 13:43 modules.usbmap
lrwxrwxrwx. 1 root root 5 Dec 12 13:42 source -> build
drwxr-xr-x. 2 root root 4096 Nov 21 22:41 updates
drwxr-xr-x. 2 root root 4096 Dec 12 13:42 vdso
drwxr-xr-x. 2 root root 4096 Nov 21 22:41 weak-updates
[root#xx libreswan-3.7]# ls /usr/src/kernels/
[root#xx libreswan-3.7]#
Notice that the "source" link is also broken because it points to build.
cd /lib/modules/2.6.32-431.el6.x86_64
sudo rm build
sudo ln -s ../../../usr/src/kernels/2.6.32-431.29.2.el6.x86_64/ build
The above commands fixed the issue for me
But basically you must be able to use any version of 2.6.32* directory in the last command.
Thanks to Nighthawk663.
I have the same problem in ./configure --with-linux=/lib/modules/uname -r/build/. It says "not a file..." too.
Reason:
The kernel head files are missing for the current kernel.
How I solved it:
find current kernel: uname -r
yum install kernel-devel-$(uname -r)
you may not find it...
just google that version of kernel-devel-... download the rpm file, and do
rpm -i kernel-devel-xxxx.rpm
Then it works for me!
/usr/lib/modules/your-kernel-edition/build is a link file.
the link file exists. but the target file might not exists. So It is ok to see the link file, but the folder can not be changed into it (cd).
Similar Example on fedora 29.
lrwxrwxrwx. 1 root root 40 Oct 21 07:38 /usr/lib/modules/4.18.16-300.fc29.x86_64/build -> /usr/src/kernels/4.18.16-300.fc29.x86_64
Just install kernel-devel.
Example.
sudo dnf install kernel-devel-$(uname -r)
Because the link is not with your kernel version.
Delete the wrong link.
$ rm build`
Use $ uname -r to check the kernel version
Build new link with your kernel version.
$ ln -s ../../../usr/src/kernels/($(uname -r)/ build
Done

what is the difference between java-1.7.0-openjdk-i386 and java-7-openjdk-i386

when i install netbeans it gives me the option to select the java environment, i have 3 options, the oracle java and these two (java-1.7.0-openjdk-i386 and java-7-openjdk-i386). what is the difference between these two?The os if ubuntu.
The two OpenJDK are same. However OpenJDK is slightly different from Oracle JDK. Read this post for more clarification.
The reason why you are getting two options for OpenJDK is PROBABLY that you have two copies of OpenJDK installed (or two different references to the same directory on your system.)
For further investigation, try to ls -lh /usr/lib/jvm. The /usr/lib/jvm is usually the directory where Java gets installed. Check if one of them is a symbolic link. Also, check in netbeans the location of the two JDK and see if in fact you have two versions or references of Java on the system.
For example, here is the output of ls -lh on my system:
ls -lh
total 24K
lrwxrwxrwx 1 root root 26 Sep 10 13:41 default-java -> /usr/lib/jvm/java-7-oracle
lrwxrwxrwx 1 root root 18 Mar 13 2012 java-1.5.0-gcj -> java-1.5.0-gcj-4.6
drwxr-xr-x 7 root root 4.0K Aug 22 2012 java-1.5.0-gcj-4.6
lrwxrwxrwx 1 root root 19 Jun 26 2012 java-1.6.0-openjdk-i386 -> java-6-openjdk-i386
drwxr-xr-x 3 root root 4.0K Feb 15 10:52 java-6-openjdk-common
drwxr-xr-x 7 root root 4.0K Feb 15 10:52 java-6-openjdk-i386
drwxr-xr-x 8 ankit ankit 4.0K Jun 6 2012 java-6-sun
drwxr-xr-x 5 root root 4.0K Aug 22 2012 java-7-openjdk-i386
drwxr-xr-x 8 root root 4.0K Feb 20 10:40 java-7-oracle
lrwxrwxrwx 1 root root 12 Mar 13 2012 java-gcj -> java-gcj-4.6
lrwxrwxrwx 1 root root 18 Apr 16 2012 java-gcj-4.6 -> java-1.5.0-gcj-4.6
As you can see java-1.6.0-openjdk-i386 is just a symbolic link/reference to another directory named java-6-openjdk-i386
You installed it twice
From openjdk, following instructions from here
sudo apt-get install openjdk-7-jdk
From Stackoverflow, following instructions from here
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
Would recommend the second one and remvong the first one by typing
sudo apt-get remove openjdk-7-jdk.