Python Pandas – Missing required dependencies [numpy] 1

Python Pandas – Missing required dependencies [numpy] 1

I had this same issue immediately after upgrading pandas to 0.19.2. I fixed it with the following install/uninstall sequence from the windows cmd line:

pip uninstall pandas -y
pip uninstall numpy -y
pip install pandas
pip install numpy

This also broke my matplotlib install so I uninstalled/installed that as well.

Very odd behavior for a seemingly routine upgrade.

What happens if you try to import numpy?

Have you tried

pip install --upgrade numpy
pip install --upgrade pandas

Python Pandas – Missing required dependencies [numpy] 1

I had to install this other package:

Python Pandas – Missing required dependencies [numpy] 1

sudo apt-get install libatlas-base-dev

Seems like it is a dependency for numpy but the pip or apt-get dont install it automatically for whatever reason.

How can I remove a key from a Python dictionary?

How can I remove a key from a Python dictionary?

To delete a key regardless of whether it is in the dictionary, use the two-argument form of dict.pop():

my_dict.pop(key, None)

This will return my_dict[key] if key exists in the dictionary, and None otherwise. If the second parameter is not specified (i.e. my_dict.pop(key)) and key does not exist, a KeyError is raised.

To delete a key that is guaranteed to exist, you can also use:

del my_dict[key]

This will raise a KeyError if the key is not in the dictionary.

Specifically to answer is there a one line way of doing this?

if key in my_dict: del my_dict[key]

…well, you asked πŸ˜‰

You should consider, though, that this way of deleting an object from a dict is not atomicβ€”it is possible that key may be in my_dict during the if statement, but may be deleted before del is executed, in which case del will fail with a KeyError. Given this, it would be safest to either use dict.pop or something along the lines of

try:
    del my_dict[key]
except KeyError:
    pass

which, of course, is definitely not a one-liner.

How can I remove a key from a Python dictionary?

How can I remove a key from a Python dictionary?

It took me some time to figure out what exactly my_dict.pop(key, None) is doing. So Ill add this as an answer to save others googling time:

pop(key[, default])

If key is in the dictionary, remove it and return its value, else
return default. If default is not given and key is not in the
dictionary, a KeyError is raised.

Documentation

How to disable Python warnings?

How to disable Python warnings?

Look at the Temporarily Suppressing Warnings section of the Python docs:

If you are using code that you know will raise a warning, such as a deprecated function, but do not want to see the warning, then it is possible to suppress the warning using the catch_warnings context manager:

import warnings

def fxn():
    warnings.warn(deprecated, DeprecationWarning)

with warnings.catch_warnings():
    warnings.simplefilter(ignore)
    fxn()

I dont condone it, but you could just suppress all warnings with this:

import warnings
warnings.filterwarnings(ignore)

Ex:

>>> import warnings
>>> def f():
...     print(before)
...     warnings.warn(you are warned!)
...     print(after)
...
>>> f()
before
<stdin>:3: UserWarning: you are warned!
after
>>> warnings.filterwarnings(ignore)
>>> f()
before
after

Theres the -W option.

python -W ignore foo.py

How to disable Python warnings?

You can also define an environment variable (new feature in 2010 – i.e. python 2.7)

How to disable Python warnings?

export PYTHONWARNINGS=ignore

Test like this: Default

$ export PYTHONWARNINGS=default
$ python
>>> import warnings
>>> warnings.warn(my warning)
__main__:1: UserWarning: my warning
>>>

Ignore warnings

$ export PYTHONWARNINGS=ignore
$ python
>>> import warnings
>>> warnings.warn(my warning)
>>> 

For deprecation warnings have a look at how-to-ignore-deprecation-warnings-in-python

Copied here…

From documentation of the warnings module:

 #!/usr/bin/env python -W ignore::DeprecationWarning

If youre on Windows: pass -W ignore::DeprecationWarning as an argument to Python. Better though to resolve the issue, by casting to int.

(Note that in Python 3.2, deprecation warnings are ignored by default.)

Or:

import warnings

with warnings.catch_warnings():
    warnings.filterwarnings(ignore, category=DeprecationWarning)
    import md5, sha

yourcode()

Now you still get all the other DeprecationWarnings, but not the ones caused by:

import md5, sha

python – How to convert string to binary?

python – How to convert string to binary?

Something like this?

>>> st = hello world
>>>  .join(format(ord(x), b) for x in st)
1101000 1100101 1101100 1101100 1101111 100000 1110111 1101111 1110010 1101100 1100100

#using `bytearray`
>>>  .join(format(x, b) for x in bytearray(st, utf-8))
1101000 1100101 1101100 1101100 1101111 100000 1110111 1101111 1110010 1101100 1100100

If by binary you mean bytes type, you can just use encode method of the string object that encodes your string as a bytes object using the passed encoding type. You just need to make sure you pass a proper encoding to encode function.

In [9]: hello world.encode(ascii)                                                                                                                                                                       
Out[9]: bhello world

In [10]: byte_obj = hello world.encode(ascii)                                                                                                                                                           

In [11]: byte_obj                                                                                                                                                                                           
Out[11]: bhello world

In [12]: byte_obj[0]                                                                                                                                                                                        
Out[12]: 104

Otherwise, if you want them in form of zeros and ones –binary representation– as a more pythonic way you can first convert your string to byte array then use bin function within map :

>>> st = hello world
>>> map(bin,bytearray(st))
[0b1101000, 0b1100101, 0b1101100, 0b1101100, 0b1101111, 0b100000, 0b1110111, 0b1101111, 0b1110010, 0b1101100, 0b1100100]
 

Or you can join it:

>>>  .join(map(bin,bytearray(st)))
0b1101000 0b1100101 0b1101100 0b1101100 0b1101111 0b100000 0b1110111 0b1101111 0b1110010 0b1101100 0b1100100

Note that in python3 you need to specify an encoding for bytearray function :

>>>  .join(map(bin,bytearray(st,utf8)))
0b1101000 0b1100101 0b1101100 0b1101100 0b1101111 0b100000 0b1110111 0b1101111 0b1110010 0b1101100 0b1100100

You can also use binascii module in python 2:

>>> import binascii
>>> bin(int(binascii.hexlify(st),16))
0b110100001100101011011000110110001101111001000000111011101101111011100100110110001100100

hexlify return the hexadecimal representation of the binary data then you can convert to int by specifying 16 as its base then convert it to binary with bin.

python – How to convert string to binary?

We just need to encode it.

python – How to convert string to binary?

string.encode(ascii)

macos – How to change default Python version?

macos – How to change default Python version?

[updated for 2021]

(Regardless if you are on Mac, Linux, or Windows:)

If you are confused about how to start the latest version of python, on most platforms it is the case that python3 leaves your python2 installation intact (due to the above compatibility reasons); thus you can start python3 with the python3 command.

Historically…

The naming convention is that generally, most scripts will call python2 or python3 explicitly. This happened due to a need for backwards compatibility.

Even though technically python doesnt even guarantee backwards compatibility between minor versions, Python3 really breaks backwards compatibility. At the time, programs invoking python were expecting python2 (which was the main version at the time). Extremely old systems may have programs and scripts which expect python=python2, and changing this would break those programs and scripts.

At the time this answer was written, OP should not have changed this due to maintaining compatibility for old scripts.

Circa year 2021…

Nowadays, many years after the python2->python3 transition, most software explicitly refers to python2 or python3 (at least on Linux). For example, they might call #!/usr/bin/env python2 or #!/usr/bin/env python3. This has for example (python-is-python3-package) freed up the python command to be settable to a user default, but it really depends on the operating system.

The prescription for how distributions should handle the python command was written up in 2011 as PEP 394 — The python Command on Unix-Like Systems. It was last updated in June 2019.

Basically if you are writing a library, you should use the most specific version(s) of python you can use. Otherwise as an end user, you should feel free to rename this for your own personal use (though your OS or distribution may not make that easy).

Shell alias:

You could, however, make a custom alias in your shell. The way you do so depends on the shell, but perhaps you could do alias py=python3, and put it in your shell startup file. This will only work on your local computer (as it should), and is somewhat unnecessary compared to just typing it out (unless you invoke the command constantly).

Confused users should not try to create aliases or virtual environments or similar that make python execute python3; this is poor form.This is acceptable nowadays, but PEP 394 suggests encouraging users to use a virtualenv instead.

Different 3.* versions, or 2.* versions:

In the extremely unlikely case that if someone comes to this question with two python3 versions e.g. 3.1 vs 3.2, and you are confused that you have somehow installed two versions of python, this is possibly because you have done manual and/or manual installations. You can use your OSs standard package/program install/uninstall/management facilities to help track things down, and perhaps (unless you are doing dev work that surprisingly is impacted by the few backwards-incompatible changes between minor versions) delete the old version (or do make uninstall if you did a manual installation). If you require two versions, then reconfigure your $PATH variable so the default version you want is in front; or if you are using most Linux distros, the command you are looking for is sudo update-alternatives. Make sure any programs you run which need access to the older versions may be properly invoked by their calling environment or shell (by setting up the var PATH in that environment).

A bit about $PATH

sidenote: To elaborate a bit on PATH: the usual ways that programs are selected is via the PATH (echo $PATH on Linux and Mac) environment variable. You can always run a program with the full path e.g. /usr/bin/ some args, or cd /usr/bin then ./ some args (replace blank with the echo program I mentioned above for example), but otherwise typing some args has no meaning without PATH env variable which declares the directories we implicitly may search-then-execute files from (if /usr/bin was not in PATH, then it would say : command not found). The first matching command in the first directory is the one which is executed (the which command on Linux and Mac will tell you which sub-path this is). Usually it is (e.g. on Linux, but similar on Mac) something like /usr/bin/python which is a symlink to other symlinks to the final version somewhere, e.g.:

% echo $PATH
/usr/sbin:/usr/local/bin:/usr/sbin:usr/local/bin:/usr/bin:/bin

% which python
/usr/bin/python
% which python2
/usr/bin/python2
% ls -l /usr/bin/python
lrwxrwxrwx 1 root root 7 Mar  4  2019 /usr/bin/python -> python2*
% ls -l /usr/bin/python2  
lrwxrwxrwx 1 root root 9 Mar  4  2019 /usr/bin/python2 -> python2.7*
% ls -l /usr/bin/python2.7
-rwxr-xr-x 1 root root 3689352 Oct 10  2019 /usr/bin/python2.7*

% which python3         
/usr/bin/python3
% ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 9 Mar 26  2019 /usr/bin/python3 -> python3.7*
% ls -l /usr/bin/python3.7
-rwxr-xr-x 2 root root 4877888 Apr  2  2019 /usr/bin/python3.7*

% ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       7 Mar  4  2019 /usr/bin/python -> python2*
lrwxrwxrwx 1 root root       9 Mar  4  2019 /usr/bin/python2 -> python2.7*
-rwxr-xr-x 1 root root 3689352 Oct 10  2019 /usr/bin/python2.7*
lrwxrwxrwx 1 root root       9 Mar 26  2019 /usr/bin/python3 -> python3.7*
-rwxr-xr-x 2 root root 4877888 Apr  2  2019 /usr/bin/python3.7*
lrwxrwxrwx 1 root root      33 Apr  2  2019 /usr/bin/python3.7-config -> x86_64-linux-gnu-python3.7-config*
-rwxr-xr-x 2 root root 4877888 Apr  2  2019 /usr/bin/python3.7m*
lrwxrwxrwx 1 root root      34 Apr  2  2019 /usr/bin/python3.7m-config -> x86_64-linux-gnu-python3.7m-config*
lrwxrwxrwx 1 root root      16 Mar 26  2019 /usr/bin/python3-config -> python3.7-config*
lrwxrwxrwx 1 root root      10 Mar 26  2019 /usr/bin/python3m -> python3.7m*
lrwxrwxrwx 1 root root      17 Mar 26  2019 /usr/bin/python3m-config -> python3.7m-config*

sidenote2: (In the rarer case a python program invokes a sub-program with the subprocess module, to specify which program to run, one can modify the paths of subprocesses with sys.path from the sys module or the PYTHONPATH environment variable set on the parent, or specifying the full path… but since the path is inherited by child processes this is not remotely likely an issue.)

Check the location of python 3

$ which python3
/usr/local/bin/python3

Write alias in bash_profile

vi ~/.bash_profile  
alias python=/usr/local/bin/python3

Reload bash_profile

source ~/.bash_profile

Confirm python command

$ python --version
Python 3.6.5

macos – How to change default Python version?

On Mac OS X using the python.org installer as you apparently have, you need to invoke Python 3 with python3, not python. That is currently reserved for Python 2 versions. You could also use python3.2 to specifically invoke that version.

$ which python
/usr/bin/python
$ which python3
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3
$ cd /Library/Frameworks/Python.framework/Versions/3.2/bin/
$ ls -l
total 384
lrwxr-xr-x  1 root  admin      8 Apr 28 15:51 2to3@ -> 2to3-3.2
-rwxrwxr-x  1 root  admin    140 Feb 20 11:14 2to3-3.2*
lrwxr-xr-x  1 root  admin      7 Apr 28 15:51 idle3@ -> idle3.2
-rwxrwxr-x  1 root  admin    138 Feb 20 11:14 idle3.2*
lrwxr-xr-x  1 root  admin      8 Apr 28 15:51 pydoc3@ -> pydoc3.2
-rwxrwxr-x  1 root  admin    123 Feb 20 11:14 pydoc3.2*
-rwxrwxr-x  2 root  admin  25624 Feb 20 11:14 python3*
lrwxr-xr-x  1 root  admin     12 Apr 28 15:51 python3-32@ -> python3.2-32
lrwxr-xr-x  1 root  admin     16 Apr 28 15:51 python3-config@ -> python3.2-config
-rwxrwxr-x  2 root  admin  25624 Feb 20 11:14 python3.2*
-rwxrwxr-x  1 root  admin  13964 Feb 20 11:14 python3.2-32*
lrwxr-xr-x  1 root  admin     17 Apr 28 15:51 python3.2-config@ -> python3.2m-config
-rwxrwxr-x  1 root  admin  25784 Feb 20 11:14 python3.2m*
-rwxrwxr-x  1 root  admin   1865 Feb 20 11:14 python3.2m-config*
lrwxr-xr-x  1 root  admin     10 Apr 28 15:51 pythonw3@ -> pythonw3.2
lrwxr-xr-x  1 root  admin     13 Apr 28 15:51 pythonw3-32@ -> pythonw3.2-32
-rwxrwxr-x  1 root  admin  25624 Feb 20 11:14 pythonw3.2*
-rwxrwxr-x  1 root  admin  13964 Feb 20 11:14 pythonw3.2-32*

If you also installed a Python 2 from python.org, it would have a similar framework bin directory with no overlapping file names (except for 2to3).

$ open /Applications/Python 2.7/Update Shell Profile.command
$ sh -l
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
$ which python3
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3
$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ cd /Library/Frameworks/Python.framework/Versions/2.7/bin
$ ls -l
total 288
-rwxrwxr-x  1 root  admin    150 Jul  3  2010 2to3*
lrwxr-x---  1 root  admin      7 Nov  8 23:14 idle@ -> idle2.7
-rwxrwxr-x  1 root  admin    138 Jul  3  2010 idle2.7*
lrwxr-x---  1 root  admin      8 Nov  8 23:14 pydoc@ -> pydoc2.7
-rwxrwxr-x  1 root  admin    123 Jul  3  2010 pydoc2.7*
lrwxr-x---  1 root  admin      9 Nov  8 23:14 python@ -> python2.7
lrwxr-x---  1 root  admin     16 Nov  8 23:14 python-config@ -> python2.7-config
-rwxrwxr-x  1 root  admin  33764 Jul  3  2010 python2.7*
-rwxrwxr-x  1 root  admin   1663 Jul  3  2010 python2.7-config*
lrwxr-x---  1 root  admin     10 Nov  8 23:14 pythonw@ -> pythonw2.7
-rwxrwxr-x  1 root  admin  33764 Jul  3  2010 pythonw2.7*
lrwxr-x---  1 root  admin     11 Nov  8 23:14 smtpd.py@ -> smtpd2.7.py
-rwxrwxr-x  1 root  admin  18272 Jul  3  2010 smtpd2.7.py*

Related posts

How to check sbt version?

How to check sbt version?

$ sbt sbtVersion

This prints the sbt version used in your current project, or if it is a multi-module project for each module.

$ sbt inspect sbtVersion
[info] Set current project to jacek (in build file:/Users/jacek/)
[info] Setting: java.lang.String = 0.13.1
[info] Description:
[info]  Provides the version of sbt.  This setting should be not be modified.
[info] Provided by:
[info]  */*:sbtVersion
[info] Defined at:
[info]  (sbt.Defaults) Defaults.scala:68
[info] Delegates:
[info]  *:sbtVersion
[info]  {.}/*:sbtVersion
[info]  */*:sbtVersion
[info] Related:
[info]  */*:sbtVersion

You may also want to use sbt about that (copying Mark Harrahs comment):

The about command was added recently to try to succinctly print the
most relevant information, including the sbt version.

sbt about then enter to get SBT version

enter

How to check sbt version?

Running the command, sbt sbt-version will simply output your current directory and the version number.

$ sbt sbt-version
[info] Set current project to spark (in build file:/home/morgan/code/spark/)
[info] 0.13.8

Related posts

continuous deployment – Trouble trying to run queued Github Actions

continuous deployment – Trouble trying to run queued Github Actions

I see here the following solutions:

  1. You can sleep your dependant workflow to simulate a waiting for
    1st workflow. wait-action might help
    you with that.
  2. You can try to trigger second action from the first action (instead of trigger it on
    push).

But all these options tbh are more like hacks. GitHub Actions are designed to run in parallel and if you want to run actions in specific order you should consider to use jobs instead and use needs property to make a dependency between them. Example:

jobs:
  job1:
    name: Run 1st job
  job2:
    name: Run 2nd job
    needs: job1

Documentation – needs

You can use concurrency.

name: CI

on:
  pull_request:
    branches: [main]

concurrency: ci

jobs:

Documentation

continuous deployment – Trouble trying to run queued Github Actions

Related Posts

Git diff all local uncommitted changes

Git diff all local uncommitted changes

Taken from this answer, to a similar (but I dont think duplicate) question, I think what youre looking for is:

git diff HEAD

This will show you all the differences between your current working directory (i.e. your staged and unstaged changes) and the HEAD commit.

Or – if you prefer to match the syntax in your question, this would do the same thing:

git diff master

(where master is your current branch).

Git diff all local uncommitted changes

Related posts

python – Issues with Anaconda install – Failed to create Anaconda menus

python – Issues with Anaconda install – Failed to create Anaconda menus

2.5 years later, I had the same problem installing v2019.07, but the version actually doesnt matter. Anaconda has had this bug in the installer for a long time.

  • 2019.07 successfully installed on one of my dev boxes
  • 2019.07 failed to create menus on a second dev box with a very similar environment. Both Anaconda and Miniconda failed. I tried everything in this thread, and then some.

Finally I went to the download archive and grabbed 2019.03, which installed with no issues. This fixed it for me, your mileage may vary.

Could you try choosing run as administrator before clicking Anaconda 3 installation? That fixed mine.

python – Issues with Anaconda install – Failed to create Anaconda menus

I was also facing the same issue while installing Anaconda 3.5, please follow the steps below before you start installation :

  1. Delete old Python versions from your PC/Laptop
  2. Clear path variables which have created on your PC
  3. Turn off your anti virus program before you start installation
  4. If you have JDK installed on your machine, uninstall it, also delete JAVA path created in variable

Related Posts

git – How to add a GitHub personal access token to Visual Studio Code

git – How to add a GitHub personal access token to Visual Studio Code

Follow these simple steps to set up GitHub authentication with a personal access token:

  1. Open a command line window on your PC or Terminal on Mac
  2. Set the current directory to your project root
    cd C:UsersGiddysourcerepoMySampleProject
    
  3. Run the command to set remote access via a token
    git remote set-url origin https://username:[email protected]/username/repository.git
    

    Example:

    git remote set-url origin https://sampleuser:a7b19929***[email protected]/sampleuser/sampleproject.git
    

Tested on Visual Studio Code (Mac)

no need for an extra extension. I only trust official extensions, sorry.
GitHub extension by KnisterPeter

  1. Generate a personal access token from github.com
  2. Make sure to save your access token (e.g., ghp_pVC*****)
  3. Open your project with Visual Studio Code or navigate to your project in the terminal, cd ~/path/to/your/project
  4. In the Visual Studio Code terminal, git remote set-url origin https://<personal_access_token>@github.com/<your_username or organization_name>/<repo_name>.git
  5. Now you can try git push

Note:

When generating a personal access token, make sure to enable workflow:

Enter

Hint

You can type git remote -v to see your origin or upstream.

origin  https://github.com/<username>/<repo_name>.git (fetch)
origin  https://github.com/<username>/<repo_name>.git (push)
upstream        https://github.com/<username>/<repo_name>.git (fetch)
upstream        https://github.com/<username>/<repo_name>.git (push)

Also after setting git remote set-url origin https://<personal_access_token>@github.com/<your_username>/<repo_name>.git

Your git remote -v should be something like:

origin  https://<your_personal_access_token>@github.com/<username>/<repo_name>.git (fetch)
origin  https://<your_personal_access_token>@github.com/<username>/<repo_name>.git (push)

git – How to add a GitHub personal access token to Visual Studio Code

Related posts