mprof run <executable> gets me "Command not found" - python-3.x

I am using Ubuntu 18.04 and Python 3. I have installed memory_profiler using the following command:
pip3 install -U memory_profiler
I was able to run python3 -m memory_profiler <executable> from the command line with no issues. However, if I try mprof run <executable> I get the following output:
Command 'mprof' not found, did you mean:
command 'gprof' from deb binutils
command 'pprof' from deb tau
command 'mlprof' from deb mlton-tools
command 'sprof' from deb libc-dev-bin
command 'prof' from deb profphd
Try: sudo apt install <deb name>
I am following the steps in the documentation of memory_profiler here but it's not working. Is there any extra step given the fact that I use Python 3?

One way to make it work is the following. Instead of mprof run <executable>, the following works:
python3 /home/myuser/.local/lib/python3.6/site-packages/mprof.py run <executable>
You must replace myuser with the appropriate value. Your full path may differ. You need to find where is mprof.py. The general command is: python3 /full/path/to/mprof.py run <executable>.

Related

How to get the python3 path in ubuntu without which command

Problem:
I want to get the python3 path in my Ubuntu VM. Like /usr/xyz/python3
More Information:
I dont see the 'which' command present in my envt.
I tried to 'sudo apt install which', but it fails saying that no such package found.
Get path of the executable python binary
Python code
import sys
print(sys.executable)
Command
python -c "import sys; print(sys.executable)"
sudo apt install which is failing because which is part of debianutils; most executables don't come as their own package.
sudo apt install debianutils
If you use bash, you can just do :
type -p python
The where and which commands are often an alias to the inbuilt bash command type.
I have it also as app in busybox on most embedded devices.
Also tablets and smartfons with the app: ConnectBot
If present on your machine too; then: type -p python3
But anyway, the correct/recommended way to make a SHEBANG is not to use type, where or which.
If your PATH environment variable targets the usually folders for installed executables just use: #!/usr/bin/env python3
Example: test.py
#!/usr/bin/env python3
import sys
print('No error - But i return 1 and not 0')
sys.exit(1)
Making than executable with: chmod +x test.py
And execute it...
$ ./test.py
No error - But i return 1 and not 0

opengv installation not in pip3 list

I have a question. I followed the http://laurentkneip.github.io/opengv/
installation manual. And i did correct the path by using the command
cmake ../opengv -DBUILD_PYTHON=ON -DPYBIND11_PYTHON_VERSION=3.7 -DPYTHON_INSTALL_DIR=/usr/local/lib/python3.7/dist-packages/
and I also ran the command
sudo ln -s /usr/local/lib/python3.7/dist-packages/pyopengv.cpython-37m-x86_64-linux-gnu.so
to bring the built package in the opengv/build/lib to the python3-package....
But I really have no idea why!! There is no opengv in the pip3 list???
The final problem was that I can not import pyopengv in openSFM...
But the first problem is I think is because there is no opengv in pip3 list..

csvkit in2csv command not working

I followed installment instructions mentioned here
Its a simple pip install command
After that I went to my linux terminal and wrote in2csvbut got the following error:
/usr/bin/in2csv: No such file or directory
Originally I tried to install it using the command:
sudo apt-get install python3-csvkit
And the in2csv command used to work on terminal, but it appears to work under python 3 installation and I need it under my python2.7.
so I uninstalled the python3-csvkit, and installed it again using pip install, but again its not working from terminal, this way.
Any ideas why, and how to solve it?
in2csv command manual: here
I just had this problem and solved with:
sudo pip install csvkit
Without the sudo pip installs csvkit in /home/username/.local/lib/python2.7/site-packages and probably puts the executable in /home/username/.local/bin. You could avoid the sudo by adding that to your shell PATH.

Can't find Python.h when compiling PyCaffe on Ubuntu 14.04

I'm trying to install PyCaffe for Python 3.5.3 on AWS EC2 with Ubuntu 14.04 without Anaconda, following the installation instructions.
I successfully compiled it on the same machine for Python 2.7 but when compiling for version 3.5 I get the following error:
ubuntu#ip-172-31-3-227:~/caffe$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:1:52: fatal error: Python.h: No such file or directory
#include <Python.h> // NOLINT(build/include_alpha)
I saw this post and performed:
sudo apt-get install python3-dev
I found this, so I performed the equivalent command for Python 3.5:
for req in $(cat requirements.txt); do sudo pip3.5 install $req; done
All installations worked but it didn't fix the problem.
I many other posts on similar problems but not this exact problem (so if you find something please check that it's really the same situation before rushing to say I didn't look well enough).
P.S.
I also saw this post but I don't understand which directories to add to the path.
When you do a pip install package,when pip finds new version,it uninstall the current one(dateutil in your case) when the package was installed using certain permission,pip needs the same permission to uninstall/upgrade it.
A quick fix would be to change this
`for req in $(cat requirements.txt); do pip3.5 install $req; done` to
for req in $(cat requirements.txt); do sudo pip3.5 install $req; done
It seems you dont have permission to access /usr/local/lib/python3.5/ folder as user,the packages that goes in /usr/local are required by the system but only available to you and only you on the system, i assume since only only they are restricted to you and pip want to access assuming that no restriction is there,then it get permission denied ,so you might consider doing
for req in $(cat requirements.txt); do pip3.5 --user yourusername install $req; done
the alternative is to remove any restriction to execute and write on that folder
by doing chmod -R 777 /usr/local/lib/python3.5/ which is usually not recommended but the problem you need pip to be able to read,write,execute anything in that folder.

Yum crashed with Keyboard Interrupt error

I installed the newer version of python (3.2.3) than the one available in Fedora16 (python2.7)
And now yum stops working. It shows the following error.
[root#localhost yum-3.4.3]# yum
File "/usr/bin/yum", line 30
except KeyboardInterrupt, e:
^
SyntaxError: invalid syntax
Please advice as how to resolve the error. It would be helpful as I am not able to update or install any package.
Because yum does not support Python3.
You can run command vi /usr/bin/yum, change /usr/bin/python to /usr/bin/python2 in first line.
Thus you can run the command yum by Python2 instead of Python3.
Note however that this will make your setup unsupported and thus unmaintainable (as does what you did). You will likely have other similar problems in the future with other system packages.
If you want to use an alternative Python installation, consider installing it into /usr/local, /opt or using pyenv.
This issue happens when user upgrades to python3, Just simply edit the file --> /usr/bin/yum and change to first line to --> "#!/usr/bin/python2"
The above solution wouldn't solve the all yum dependency problems, its better to run the below commands.
sudo ln -s /usr/local/bin/python3 /usr/bin/python3 (Mark latest python as python3)
sudo ln -sf /usr/bin/python2.7 /usr/bin/python (nake 2.7 as default python)
THanks,
Daman
I'm guessing you installed Python 3.2.3 from source and used "make install" as the last command. That command has the unfortunate side-effect of replacing the system installed version command "python" with the new version. Using "make altinstall" doesn't replace "python".
The command "python" is just a symbolic link to "python2", which in turn is a symbolic link to "python2.7". You should be able to restore "python" by executing the following command:
cd /usr/bin
sudo ln -s python2 python
Thanks Damanvir! Changing the line in /usr/bin/yum worked!
This is a little off topic and might be removed but it might help someone.
These are the steps I used to install Python 3.7 on Centos and fix the yum error.
Download from https://www.python.org/
tar -xvf
./configure --enable-optimizations
make
make install
OR
make altinstall
make altinstall is used to prevent replacing the default python binary file /usr/bin/python.
cd /usr/bin
Remove the current symbolic link to the previous version
rm python
OUTPUT: rm: remove symbolic link ‘python’? y
Find the location of the new version
whereis python3.7
OUTPUT: python3: /usr/local/bin/python3.7
Verify this is correct
/usr/local/bin/python3.7 --version
OUTPUT: Python 3.7.0
Create a symbolic link to the location of the new version
ln -s /usr/local/bin/python3.7 python
python --version
OUTPUT: Python 3.7.0
Yum commands will show the following error:
File "/bin/yum", line 30
except KeyboardInterrupt, e:
SyntaxError: invalid syntax
Change the top line of this file from using python to python2
vi /usr/bin/yum
#!/usr/bin/python2
Reference: https://tecadmin.net/install-python-3-7-on-centos/
The real answer - to ensure that you are back on a supportable version of python (in the event you are looking at this for an issue with RHEL 7).
cd /usr/bin
sudo unlink python
sudo ln -s python2 python
Your yum looks for python2. Let's use 'alternatives' to switch between pythons2 and python3.
run --> sudo alternatives --config python
Enter to keep the current selection[+], or type selection number:
If you don't configure it. How to do that?
sudo alternatives --install /usr/bin/python python
/usr/local/bin/python3.8 60
sudo alternatives --install
/usr/bin/python python /usr/bin/python2 50
It's only a binary link issue. You can copy the working /usr/bin/python2 from any system and copy to current system location /usr/bin/python2
#cd /usr/bin
#ln -s python2 python

Resources