I installed package yolk with the help of pip
python -m pip install yolk
I want to use in cmd to do something like:
python -m yolk -l
I get:
No module named yolk.__main__; 'yolk' is a package and cannot be directly executed
Can I still run commands from this package in cmd? The documentation seems to imply that this is how you run this package?
python -m yolk -l
The documentation seems to imply that this is how you run this package?
That is not what the documentation says. It says to use the console script yolk directly. But indeed it is always better to call the executable module instead, so after looking at the code, it seems to be:
path/to/pythonX.Y -m yolk.cli
yolk seems to be available only on python 2
python --version # check python 2
pip install virtualenv # install virtual environment on python 2
virtualenv venv # create your virtual environment
source venv/bin/activate # activate it
pip install yolk # install the package
yolk -v # use yolk's package bin commands
# ... other commands with yolk
deactivate # virtual environment
Related
First I run command pip install virtualenv then after I run python -m virtualenv venv, I get this following error msg
"/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named virtualenv"
Cuurently, I'm using python v2.7.16 and when I run pip freeze | grep virtualenv , I get virtualenv==20.4.2 so virtualenv is there. When I run which python I get /usr/bin/python and I don't have .bash_profile when I run ls -a. I am using mac. What could be the reasons python not recognizing virtualenv when it's there?
You may create .bash_profile and it is auto-recognised by the macintosh machine.
Please also run which pip and make sure the pip is in the same bin as your python (/usr/bin/python)
The bottom line is pip used to install a package by default will install the packages in the bin directory that also stored your python executable.
I am trying to install numpy, nltk, etc packages for Python 2 to run a code. But I have Python3 as well and the path variable is set to it. When I try to use any pip install command it shows the package is available in Python3's directory.
Also, I am using VSCode, so I did not add the path variable.
I suggest you use virtual environments. Because if you read about virtual environments, you will find that they are created for such cases.
To create virtual environments, you must do the following:
Make a note of the full file path to the custom version of Python you just installed.
virtualenv -p /home/username/opt/python-2.7.15/bin/python venv
In order to use this environment’s packages/resources in isolation, you need to “activate” it. To do this, just run the following:
source venv/bin/activate (Linux)
./venv/Scripts/activate.bat (Windows)
Notice how your prompt is now prefixed with the name of your environment (venv, in our case). This is the indicator that venv is currently active, which means the python executable will only use this environment’s packages and settings.
Now run the following:
(venv) $ which python
/Users/ashkan/python-virtual-environments/venv/bin/python (in my case)
now you have access to python2.7.
The best practice for this particular problem would be virtual environments.And for that matter Pipenv would be a good option.
Install Pipenv.
$ brew install pipenv (MacOs)
$ sudo apt install pipenv (Debian)
$ sudo dnf install pipenv (Fedora)
pip install pipenv (Windows)
Creating virtual env with Pipenv.
pipenv install --python 2.7 numpy
This command will install create a virtual environment and install python 2.7(which will be used as the main interpreter once you activate the environment) along with numpy in that environment. This will avoid the packages version conflicts too.
To activate the environment
pipenv shell
If you are working in the Vs Code workspace then you should set the interpreter path(python path) to the path of the virtual environment.
when we install anything using pip. it will install dependencies for default python version. so you can change the default python version using this link https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
Hope this will solve your problem
After crating a virtual environment with python 2.7 you can install your required packages
I am trying to create a new virtual environment for a tutorial. I have installed virtualenv and virtualenvwrapper multiple times but every time I try creating a new virtual environment my terminal displays - mkvirtualenv: command not found. When I try finding out the version of virtualenv it shows virtualenv: command not found. Something similar was happening with my pip installation as well but then it got resolved when I used some command.
I would like to point out that my PATH seems to be really messed up. The PATH is pointing to /Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin. Please help.
I saw something else when I use pip show virtualenv it gives me details of the version and the author but when I use virtualenv --version it sends a virtualenv: command not found.
First of all, you will need to install virtualenv as it is a python 2 external dependency.
pip install virtualenv
this will allow you to use virtualenv globally.
Alternatively, you can use from Python 3.5+
python -m virtualenv venv
However if you dont wish to support python 2 you can use venv which is installed on from python 3.3
python3 -v venv venv
Took quite some time to figure it out but what worked for me was to install it using pip3 install instead of pip install
pip3 install virtualenv
I'm using Kali dist so I have already installed Python 2.7, 3.5 and 3.6. Commands 'python' and 'pip' are associated with Python 2.7. But the 'python3' uses Python 3.6 while pip3 is installing packages for Python 3.5.
When I tried to create an venv:
pip3 -p python3.6 virtualenv myenv
I've got an error:
no such option: -p
How can I associate pip3 with Python 3.6 instead of Python 3.5?
Your version of pip is inextricably linked to your version of Python, you cannot tell pip "use this Python" or "use that Python." If you have a version mismatch between pip3 (using Python 3.X) and python3 (being Python 3.Y), it means your problem is with multiple overlapping distributions of Python and a weirdly configured $PATH.
If you run pip3 --version it will tell you the site-packages directory and Python version number that pip3 is associated with.
If you run python3 and then execute >>> import site; site.getsitepackages(), it should print the site-packages directory your python3 is using.
If these do not match, you've got path problems and you'll need to post more information about what operating system you're on, what Python distributions you're using, and how you installed them.
Update/Summary of Comment Thread: Original poster had a distribution-bundled Python 3.6 installed alongside a self-installed Python 3.5. The pip3 on their path was associated with Python 3.6 (system Python), while the command python3 was associated with Python 3.5 (their self-installed Python). Resolution:
Run which -a python3 to find Python 3.5. Add the location of Python 3.5 to your $PATH. (Do it in .profile or .bash_profile to make it permanent.)
You can explicitly run the pip3 script with a particular Python version, by prefixing it with the appropriate python3.x command:
ldo#theon:~> pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
ldo#theon:~> python3.5 $(which pip3) --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
To install a package in the same version location that's associated with the version associated with python3, use the following:
python3 -m pip install [package]
to pick a specific version that you'd like your package to be associated with (so you're not guessing with the above):
python3.5 -m pip install [package]
python3.7 -m pip install [package]
Also, be careful because pip3 can point to different locations and may not necessarily match the location of the python3 binary. I just found that out when I did a pip3 install and it failed to import when running python3.
You can also explicitly call pip3.5, pip3.7, etc, but honestly I prefer using the python[version] -m pip install [package] method because I know that it will install the package in the location associated with whatever python3.x binary I'm using.
When you install Python3, see if there's a comment such as this:
Ignoring ensurepip failure: pip 9.0.1 requires SSL/TLS
You might see entries like this in the log:
INFO: Can't locate Tcl/Tk libs and/or headers
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _dbm _gdbm
_lzma _sqlite3 _ssl
_tkinter readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
atexit pwd time
This answer describes using ensurepip
https://stackoverflow.com/a/38250442/1607937
Also see this regarding openssl
"SSL module in Python is not available" when installing package with pip3
If you want to use only one version of python you sould probably create an alias. Add this line at the end of your ~/.bashrc flie:
alias pip='python3.6 -m pip'
Then, run source ~/.bashrc, and now pip --version will show something like:
pip xx.x.x from /usr/lib/python3/dist-packages/pip (python 3.6)
you can update line #1 from /usr/bin/pip3 to #!/usr/bin/python3.8 as below
#!/usr/bin/python3.8
# GENERATED BY DEBIAN
import sys
# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
sys.exit(main())
First find the right version of python you want to use:
$ which -a python3.6
/usr/bin/python3.6
then invoke that instance of python directly, e.g.
$ /usr/bin/python3.6 -m venv
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] ENV_DIR [ENV_DIR ...]
venv: error: the following arguments are required: ENV_DIR
Next, pip does not create virtual environments. The module venv does. Read the venv documentation for recommended usage. In your case, you might want:
$ /usr/bin/python3.6 -m venv myenv
I used sudo pip install virtualenv, then when I run virtualenv ENV in a directory, I get a Python 2 virtual enviroment.
If I use 'pip3 install virtualenv' to install virtualenv again, will it override the previous installation of virtualenv, then when I run virtualenv ENV, I get a Python 3 virtual enviroment? or will it install a new virtualenv in a different name like virtualenv3 in a different place ?
You don't need to go to those lengths. You can use Python 2's virtualenv to create a Python 3 virtual environment. Supposing you have Python 3's binary installed at /usr/local/bin/python3 then simply run
virtualenv -p /usr/local/bin/python3 ENV
and you will find that
source ENV/bin/activate
gives you the Python 3 environment you want.