on MAC OS X, py.test not recognized as a command - python

On MAC OS X 10.10; I installed pytest 2.6.4; however in Terminal If I write py.test or even py.test --version; I get the error:
-bash: py.test command not found
(a) Am I missing anything? What do I do to make the pytest tool recognizable.
I searched alot; but couldn't find any info except http://teckla.idyll.org/~t/transfer/py.test.html
I checked in the PyCharm preferences, I don't see py.test interpreter listed there. However, pip freeze displays pytest 2.6.4 installed.
(b) Is PYTHONPATH required to be set on MAC? Although I've seen setting it is not required on Windows.
Appreciate any pointers to help me resolve this.
Update: Contents of my bash_profile:
echo export PATH="HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
PATH="/Users/admin/Library/Python/2.7/lib/python/site-packages:$PATH"
PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH"
export PATH

On OS X you should do:
pip install -U pytest
or
easy_install -U pytest
http://pytest.org/latest/getting-started.html

Got it worked finally!
After downloading pytest, I ran the following commands and it worked like magic. I think,earlier, I missed putting "sudo" infront of the install command:
$python setup.py build
$sudo python setup.py install
The output said:
..
Installing py.test script to /usr/local/bin
Installing py.test-2.7 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/pytest-2.6.4-py2.7.egg
..
Using /Users/admin/Library/Python/2.7/lib/python/site-packages
Finished processing dependencies for pytest==2.6.4
My .bash_profile contents, jfyr:
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/System/Library/Frameworks/Python.framework/Versions/2.7/bin"
export PATH

For those of us trying to avoid any and all use of sudo:
Download from PyPI here and unpack.
$ cd <pytest download folder>
$python setup.py build
$python setup.py install --user
Wherever the installing output says the "py.test script" has been installed to, add to PATH in your .bash_profile (or .bashrc if you use that for environment variables).
Confirm the setup worked via $py.test --version

pip3 install -U pytest is working with version Python 3.7

I had a problem installing pytest on Mac M1 but I followed the python pip documentation and it worked. What i did was:
istalled pip via command in Pycharm terminal (I use pycharm): python3 -m pip install pytest
after installation I run the pytest from the terminal with a command : python3 -m pytest "name_of_the_file.py"
And that works. On Mac I need to prefix all commands with "python3" cause I guess Mac has its own inbuild Python but thats Python 2 so in order to run code on my Pycharm, which was Python 3 , I need that prefix in the command... not sure though I am a newbie but something along those lines I guess

Related

issue when attempting to install python library using pip [duplicate]

How can I use pip in oh-my-zsh? I was trying to install nltk through pip, but it told me zsh: command not found: pip. When I check plugins under .oh-my-zsh/custom/plugins, there is a folder named pip. I don't know what the problem is.
Edit:
$ echo $PATH
/home/xxx/bin:/usr/local/bin:/home/xxx/bin:/home/xxx/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ type pip
pip is an alias for noglob pip
Maybe you have installed both python2 and python3. python3 may have been installed later.
You may try to use pip3 instead of pip.
First, input the command:
pip3 -V
If you see the version, the pip3 can be used.
Then you can input command line to install nltk:
pip3 install nltk
I got a way to help you use pip in zsh. We can use nano to edit files. In nano, ctrl+X to save and exit
In the ~ directory, input the command:
nano .bash_profile
You may see some codes like:
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
Copy them and paste them to the end of .zshrc file by using command:
nano .zshrc
Then input the command:
pip -V
If you see the version, pip can be used.
In case you do
which pip
and it doesn't show the path, just do
which pip3
This will print the path which is /usr/local/bin/pip3
Then do open ~/.zshrc or nano ~/.bash_profile.
Make alias for pip like:
alias pip=/usr/local/bin/pip3
N.B: You copy that line above and paste in your .zshrc file.
After do source ~/.zshrc and close .zshrc
For me it's working to do
python -m pip install [package_name]
instead of
pip install [package_name]
If you installed python3.x, you should run with pip3(not pip)
So you are using oh-my-zsh framework for zsh or Z shell.
First, try the command:
pip3 -V
If you get something like this below, that means you have the pip3 package already and must be having python3 as well.
pip 22.0.4 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)
Then edit your .zprofile instead of .bashprofile as you are using zsh. This is the command.
nano ~/.zprofile
Then it should have the two alias like this.
# Setting PATH for Python 3.10
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
export PATH
alias python=python3
alias pip=pip3
Make sure you save it. Exit and Re-open you terminal. Type the command:
pip -V
It should have the same result as the pip3 -V like this:
❯ pip -V
pip 22.0.4 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)
Then you can use pip or pip3 interchangeably for installing your nltk package like this.
pip install nltk
I'm on MacOS and use ZSH. It seems pip 2.7 can't be found, although it is installed. I believe my paths to "pip" are linked wrong (I also have python3 and pip3 installed via brew).
To get around the issue I created an alias. If you don't have an .aliases file, create one in your homedir. Then open the file:
nano ~/.aliases
and add:
## PIP for python2.7 ##
alias pip="python -m pip "
You need to tell ZSH to pick up the alias file (assuming you don't have this setup already). Open your .zshrc:
nano ~/.zshrc
The add the following near the bottom of the file:
[ -f "$HOME/.aliases" ] && source "$HOME/.aliases"
From the terminal, run:
source ~/.zshrc
Or quit your terminal and reopen it.
Now you can run:
pip install <command>
Edit your rc file:
vim ~/.zshrc
Find the config plugins and delete the pip entry.
In a new terminal:
which pip
This will show you the real path of pip
If you're running into this issue, it probably is due to versioning complications. Python 2 versus Python 3 on your OS may be resolving unexpectedly. Below is a quick workaround to get you to functioning behavior.
Try using the below for Python 2:
python -m pip install <command>
Try using the below for Python 3:
pip3 install <command>
In my case my OS was Ubuntu 20.04 and the pip doesn't come with python.
So, i've installed pip through the command
sudo apt install python3-pip
and I'm done.
To ensure run pip -V or pip3 -V
My pip script is missing for some reason, so I have to install it.
$ python -m ensurepip --upgrade
More methods can be found here:pip installation
You should consider upgrading.
Enter this in your terminal
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 -m pip install --upgrade pip
and then...
Type: pip -V

Installed pytest but running `pytest` in bash returns `not found`

I am following the python-django tutorial in Vagrant (Ubuntu 18.04 / Python3.6.6). After running pip3 install pytest-django and configuring pytest.ini file, running pytest returns
Command 'pytest' not found, but can be installed with:
apt install python-pytest
Please ask your administrator.
pip3 freeze output:
pytest==3.10.0
pytest-django==3.4.3
Is there something else to the installation?
Try python -m pytest
Installing pytest via pip doesn't make it a system command, it installs it to python. The -m command runs pytest as its own command and then any proceeding script will be an argument.
I got problem when I wanted to run the following code in .sh file.
pytest-3 -s test.py
To solve it I get solution from linux itself as follows:
sudo apt install python3-pytest

CMDER not finding sudo and pip commands

So I have been using regular windows command prompt and wanted to try using bash as most forums give commands in bash and it's a little cumbersome to try to find the translation to windows. Currently trying out Spotify API and I want to run a virtual environment.
I do the following windows command and everything runs fine:
[WINDOWS]
python -m pip install virtualenv
this, does not:
[BASH]
pip install virtualenv
and I get returned bash: pip: command not found
SO I go to install pip using sudo easy_install pip and get returned bash: sudo: command not found.
I am running CMDER as admin in bash so I thought ok, I will try easy_install pip and returned bash: easy_install: command not found. SO i went to the actual python directory and went to install pip again and no luck.
Any insight on how I can address this?
[Windows]]1[Bash]2
You can try to install pip by downloading the get-pip.py from here and then run it using python get-pip.py
After that
You might need to set your Environment Variable to include PIP in your path. you can use Environment Variables in Control Panel and add the path to System Variables.
I ran into this issue as well. Not sure what causes it, but switching to cmd.exe and running pip install ... worked without issue.

Conda setuptools install changes shebangs to default python install

I'm having an issue where packages installed via setuptools to python anaconda have shebangs rewritten to the wrong location.
I have installed python anaconda and setuptools package. I have verified that python executable points to the anaconda executable
grant#DevBox2:/opt/content-analysis$ which python
/opt/anaconda2/bin/python
I need to install a custom package to my anaconda python. It is only installable via setuptools. It includes an command-line executable with the following shebang at the top:
#!/usr/bin/env python
After installing the package with the following command:
sudo python setup.py install --prefix=/opt/anaconda2
The executable (content_analysis) appears in a path reachable location. But the shebang at the top has been replaced with the hard coded location of the default python install on the machine.
grant#DevBox2:/opt/content-analysis$ which content_analysis
/opt/anaconda2/bin/content_analysis
grant#DevBox2:/opt/content-analysis$ sed -n 1,2p /opt/anaconda2/bin/content_analysis
#!/usr/local/bin/python
I have read the following post here concerning setuptools' overwrite of shebangs. The post suggests that the python executable that is first in the $PATH should be the executable that setuptools uses to replace the shebang. This doesn't seem to be the case for me however.
Note: I cannot hardcode a python executable into my python setup.py build command. I need a deployment solution that will work in any environment that has conda installed as the first python in the $PATH
I finally figured out what has been causing all my issues getting python and dependencies properly installed:
Whenever sudo is invoked before an executable, in Debian the $PATH variable is automatically changed to a secure path lookup. Here is a demonstration:
grant#DevBox2:/opt/content-analysis$ sudo sh
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
versus
grant#DevBox2:/opt/content-analysis$ sh
$ echo $PATH
/opt/anaconda2/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
So, when sudo is invoked prior to sudo python setup.py the install is reverting back to the default python.
See this post for discussion

How to run pip on windows?

How to run pip on windows?
I understand, that it may be very silly question, but all guides, entire web have same:
$ pip install <package>
But where should I find this "$"? It is not Windows console. It is not Python console. It is not different combinations of them. Where should I find this magical "$" on Windows?
When you install pip (via get-pip.py or etc) it installs into your python directory in the subfolder \Lib\site-packages. It also puts a pip.exe in your %python%\scripts folder. If you add C:\python-install-directory\scripts to your PATH you should be able to run it from the command line:
$ pip install <package>
The $ you see is the standard *nix terminal. Windows uses a > after the working directory, *nix uses a $. It is safely ignored.
Try this it helped me to solve the problem
py -m pip <your command>
"-m" should handle all your path related problems

Categories

Resources