virtualenv couldn't find python interpreter path? - python-3.x

my computer have python3.4, python3.5, python3.6, python3.7, but now i want to use python virtualenv to create a env , but it show path not found?
The image in here:

You need to provide the full path to Python, for example:
virtualenv.exe -p C:\Python37\python.exe
For git-bash the command should be slightly different:
virtualenv.exe -p /c/Python37/python.exe

First of all having multiple versions of Python is not advised especially if you cant manage them. The issue you are getting stems from the installation of the Virtualenv package. You need to use the python version that has Virtualenv in the site-packages. Examine all the site packages for the 3 versions then use the one that has virtualenv alternatively you can uninstall all the 3 versions and reinstall one I'd advise on Python 3.6 then install virtualenv via pip and try again.

Related

PIP and python installing packages

I have a CentOs system with both Python 2.7 and Python 3.4 installed. I do not have information regarding how these were installed.
However, this is the response when the following commands are issued:
whereis /usr/bin/python3
python3:
/usr/bin/python3.4
/usr/bin/python3.4m
/usr/lib/python3.4
/usr/lib64/python3.4
/usr/include/python3.4m
whereis /usr/bin/python2.7
python2:
/usr/bin/python2.7
/usr/bin/python2
/usr/lib/python2.7
/usr/lib64/python2.7
/usr/include/python2.7
/usr/share/man/man1/python2.1.gz
I am uncertain how to use PIP in this setup. Python documentation for PIP mentions it assumes that your environment is virtual.
If I want to install a module in python3.4 using PIP, what are the steps?
1. sudo as root?
2. set environmental variables?
3. etc...
Installing a Python package is fairly straightforward, you need to first verify that it's not already packaged by your distro, in your case:
yum search <module_name>
Those packages are generally named like: python-<module_name> for a Python 2 module and python3-<module_name> for a Python 3 module.
If it doesn't exist as a package, you can then rely on PyPI:
python3 -m pip install <module_name> --user
From my answer here
Let's break the this command in two parts:
python -m: Allows modules to be located using the Python module namespace for execution as scripts. The motivating examples were standard library modules such as pdb and profile. See PEP 338
--user : By default Python installs Python packages to system directories which requires root privileges, to avoid using sudo pip install (which is not recommended by the way) use this flag to make pip install packages in your home directory instead, which doesn't require any special privileges.
As a side note, if you have multiple versions of Python installed, keeping track of which Python version version pip is bound to can be a PITA, hence python -m, in this case you're sure that it's the pip bound to the Python called which will be executed.
While the previous method works (kinda), it's advised to use virtual environments because many Linux distributions (including CentOs) rely on some Python modules and you don't want to modify them unless you know what you are doing or you absolutely want to break your System.
Additionally, if you only want to "Install and Run Python Applications in Isolated Environments", you can check out pipx.
I always use pip3 when I want to directly refer to python3.
If I want to install a module in python3.4 using PIP, what are the steps? 1. sudo as root? 2. set environmental variables? 3. etc...
just this
sudo apt install python3-pip
pip3 install xyz

can't uninstall python3 in macOS

I am having trouble with my current python, so I wanted to uninstall my python and install the latest version. I installed with homebrew, so I uninstalled it with homebrew and reinstalled python 3.8.1 with the installer from the official site. Python3.8 was installed, but my python3 was not upgraded.
~ which python3
/usr/bin/python3
~ python3 --version
Python 3.7.3
I know I'm not supposed to(and I can't) manually delete things inside /usr/bin. What am I supposed to do?
When you installed Python with homebrew it told you this:
Unversioned symlinks python, python-config, pip etc. pointing to
python3, python3-config, pip3 etc., respectively, have been
installed into /usr/local/opt/python/libexec/bin
If you need a reminder, post install, you will get the same message if you run:
brew info python
It says "unversioned links are in /usr/local/opt/python/libexec/bin". That means, if you want to run Python without specifying the version, i.e. if you want to type this:
python
and this:
pip
to start Python 3 and its corresponding pip, you need to make sure your PATH has /usr/local/opt/python/libexec/bin at the start, i.e.
export PATH=/usr/local/opt/python/libexec/bin:$PATH
I could not uninstall the python3 in /usr/bin but found a workaround to give the python3 in /usr/loca/bin precedence by setting the PATH env variable as PATH=/usr/local/bin:$PATH. This gives binaries in /usr/local/bin precedence. Not a full fledged solution, but got me moving.

Why virtualenv shows all packages installed and do not install modules in virtualenv?

Question
I am not sure why when virtualenv active, pip freeze stills showing all modules when it suppose NOT to. What am I doing wrong?
On the terminal
I tried two ways to create a virtual env:
virtualenv my-virtualenv
virtualenv --no-site-packages my-virtualenv
then activate it
source my-virtualenv/bin/activate
Results
Both show all packages (when they suppose not to). Running command pip freeze I get:
(my-virtualenv)$ pip freeze
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
actionlib==1.11.9
angles==1.9.11
bondpy==1.7.19
camera-calibration==1.12.20
camera-calibration-parsers==1.11.12
catkin==0.7.6
cv-bridge==1.12.4
diagnostic-analysis==1.9.2
diagnostic-common-diagnostics==1.9.2
diagnostic-updater==1.9.2
dynamic-reconfigure==1.5.48
gazebo-plugins==2.5.13
gazebo-ros==2.5.13
...
rosnode==1.12.7
rosparam==1.12.7
rospy==1.12.7
rosservice==1.12.7
rostest==1.12.7
rostopic==1.12.7
rosunit==1.13.5
roswtf==1.12.7
tf2-ros==0.5.16
topic-tools==1.12.7
xacro==1.11.2
Running
(my-virtualenv)$ which python
/home/user/.../my-virtualenv/bin/python
(my-virtualenv)$ python -V
Python 2.7.12
and
(my-virtualenv)$ which python3
/usr/bin/python3
(my-virtualenv)$ python3 -V
Python 3.5.2
Hence, I even can use python3 when virtualenv is activated but it uses the pc installed module. Moreover, new installed packages are install in the pc and not the virtualenv and I can't install python3 in the vitualenv because it "exists" already (but in the pc).
I was having the same issue and it was because, somehow, Python configuration of ROS was generating it.
I solved it removing the source commands of ROS from the ~/.bashrc. E.g.:
source /opt/ros/melodic/setup.bash
source $HOME/ROS/aslam_ws/devel/setup.bash
By the way, I realised that, before changing anything, creating the environment from PyCharm works properly too (when in the terminal I still had the issue).
There must be a better solution but I haven't found it yet.

Rationale for having having to install the python3-venv package

Some things you should know before I ask my question:
I am utterly new to both Linux & Python, and have a hard time understanding official documentation and technical answers (but have a burning desire to deeply understand both)
I am running elementary OS 0.4.1 Loki
My Python 3 version is 3.5.2. When I search the online documentation on the venv module for python 3.5.2, I get the documentation for the 3.5.6 version. I don't understand why there is no documentation for the .2 version.
So, here's my problem. I was trying to create a virtual environment using venv and proceeded thusly:
According to Python's 3.5.6 venv module documentation, a virtual environment is created using the command pyvenv /path/to/new/virtual/environment. I tried that command and got:
The program 'pyvenv' is currently not installed. You can install it by typing: sudo apt install python3-venv
I then searched documentation for newer Python versions and tried the new venv command python3 -m venv /path/to/new/virtual/environment and got the following result:
The virtual environment was not created successfully because ensurepip is not available. On Debian/Ubuntu systems, you need to install the python3-venv package using the following command. apt-get install python3-venv
In both cases, the solution seems to be to install python3-venv. My question is: What exactly am I installing by installing python3-venv: Isn't venv already part of the Standard Library? Furthermore, why do I have to install it via apt-get if it is a Python module? It is my understanding that standard library modules are imported, not installed; and that modules external to the standard library are installed via pip. Related to this, why is ensurepip not available?
Second part of my question: if installing python3-venv is the way to go, what is the proper way to create a virtual environment using venv in Python 3.5.2: pyvenv my_virtual_environment or python3 -m venv my_virtual_environment?
Don't worry about the documentation not matching the micro version number – increments in that place are only for bugfixes, so the documentation stays the same.
Your question is interesting since venv is indeed not an optional module. My guess is that the Python version shipped with your OS (or that you installed yourself) seems to come with a stripped down or no standard library. For instance, the python3.5-minimal package doesn't appear to have it. Does your Python have the other modules in the standard library?
Edit: See also this question.
Installation can be described as "putting files onto your computer, in the right place". Importing a module, however, means that you tell Python to make available some functionality. To import a module, it must be installed (e.g. in /usr/lib/python3.5 for Python 3 on my computer), and one method for installing additional modules is via apt.
The python3 -m venv my_virtual_environment method should work in 3.5 as well and is the future-proof version, so you should probably go with that.

Installing packages with pip (Python 3.6)

I can't seem to figure out how to use pip with Python 3.6. I'm really lost and annoyed because it seems so easy. I've tried changing the path, calling for it in CMD prompt and PowerShell, but nothing seems to work.
When I type -m pip install matplotlib, for example, it says "Can't find a default Python."
try this out:
python3 -m pip install <package-name>
I hope this helps.
You can explicitly put the Python path while running virtualenv.
virtualenv --python=\path\to\python path\to\new\virtualenv\
then
source testenv/bin/activate
You can also adjust the default python version if you have multiple versions using py.exe on Windows using:
py -3
If I understand correct you are using windows. In that case, make sure that you have definend python path in Environment Variables and then make sure that you have installed pip in your system, for that check with this How do I install pip on Windows? here is good tut on how to do that. After that if you still can't use pip install <package-name> in cmd make sure that you have no restrictions on your proxy, if you have, then you could try to create pip.ini file wich would bypass you'r proxy settings, I have it like this:
Set path:
C:\Users\userName\pip # here create pip catalog
Then create pip.ini file inside pip catalog.
Then create configs:
[global]
strict-ssl=false
always-auth=false
proxy=http://proxyOfYoursUrl:8080/
trusted-host=pypi.python.org
This should help using pip thru cmd.

Resources